WEBVTT

00:01.540 --> 00:02.170
Okay.

00:02.170 --> 00:08.920
In this video I will be talking about fetching data from the localhost and I will show you why that

00:08.920 --> 00:11.530
might be a problem using our current setup.

00:11.530 --> 00:16.090
So what we have so far is we are using our localhost.

00:16.090 --> 00:17.080
So what will happen?

00:17.080 --> 00:20.230
I will do expo start here.

00:21.400 --> 00:29.320
So we have an expo opened here and normally I run it on simulator and emulator.

00:29.320 --> 00:35.110
So simulator and emulator can easily communicate with our API that I have here.

00:35.110 --> 00:37.960
So we have that running on the localhost.

00:37.960 --> 00:39.790
So what is happening now?

00:39.790 --> 00:46.930
If I will try to open this application on my phone, you will be able to see that actually on the screen.

00:46.930 --> 00:53.650
I just scan the barcode here and you can see here this is building JavaScript bundle for me.

00:56.400 --> 01:03.130
That have been finished and I have my application opened in my mobile, but I don't see a list of movies.

01:03.130 --> 01:04.750
So why this is happening?

01:04.750 --> 01:12.940
If I go here, you can see here network request failed and we can't actually get the request here because

01:12.940 --> 01:19.930
my mobile, despite the fact it is on the same network as my computer here they cannot communicate with

01:19.930 --> 01:22.150
this localhost API.

01:22.180 --> 01:24.640
So what will be our solution?

01:24.820 --> 01:31.480
Basically what we can do is we can tell this to run on a specific IP.

01:31.810 --> 01:39.460
So if you don't provide any arguments like a run server, it will run on 127 001.

01:39.460 --> 01:49.000
So our solution will be to get our IP, local IP and then use that IP for run the server so I can open

01:49.000 --> 01:56.330
the terminal here and I can type in Ipconfig and then get if.

01:57.260 --> 02:00.650
Address like this and then an zero.

02:00.650 --> 02:04.190
So if I will do it this this is my local IP.

02:04.430 --> 02:09.980
If you want to do it on the windows, it's a ipconfig like this.

02:09.980 --> 02:15.650
And then you will be able to see the same thing in the IP version four address.

02:15.650 --> 02:20.630
So if we have that IP handy for us, then we can use it.

02:20.630 --> 02:24.020
But I will also show you another thing what we can do.

02:24.050 --> 02:27.800
Remember, we have 192 160 815.

02:27.830 --> 02:30.680
You will have something similar, but not the same as I have it here.

02:30.680 --> 02:38.090
But if you go to the expo here, you can see the same IP is here, so you don't need to go to terminal

02:38.120 --> 02:41.120
to find out you already have it here.

02:41.120 --> 02:42.740
So that's your local IP.

02:42.950 --> 02:48.140
And depending on the number of devices in your network, you might have like 130 or something like that.

02:48.140 --> 02:57.600
So I have this one and once I have this, what I can do is I can go to the PyCharm and I can either,

02:57.600 --> 03:07.110
if I want to run this from here, I would normally do Python3 Manage.py run server and then I can run

03:07.110 --> 03:07.980
the server normally.

03:07.980 --> 03:14.160
But if you would like to run it on different IP, what you can do is you can use the IP and then port.

03:14.340 --> 03:18.930
So then you will run the server on this IP with that port.

03:18.930 --> 03:21.570
But we don't want to do it every single time.

03:21.570 --> 03:28.650
We will open our PyCharm so we can also do here, edit configuration and then run server and then we

03:28.650 --> 03:33.170
can pass another parameter here and then 8000 por.

03:33.180 --> 03:37.770
So if I will apply this, if I will run it now.

03:38.540 --> 03:41.330
I will stop the previous one and rerun it again.

03:42.420 --> 03:49.020
You can see I have a new my local app here and that is Django is running on.

03:49.020 --> 03:51.330
So we have a new URL.

03:51.330 --> 03:56.820
So if I will go back to my code and here I'm fetching a list of movies.

03:56.820 --> 03:58.680
So that was the previous.

03:59.490 --> 04:03.180
Now I will use my own IP here, so I will save it here.

04:06.040 --> 04:09.700
I think I need to close it and run it again.

04:11.530 --> 04:15.460
So I will scan the code and I'm building a new application now.

04:17.250 --> 04:18.720
This has been finished.

04:18.720 --> 04:22.680
And if I go here, I still have a problem here.

04:22.680 --> 04:24.330
So why this is happening?

04:24.360 --> 04:25.530
But now it's not.

04:25.590 --> 04:26.790
It's a different error.

04:26.790 --> 04:28.680
So we have unrecognized token.

04:28.680 --> 04:33.930
If I go here, you can see this invalid http host header.

04:33.930 --> 04:41.130
So what is happening now is whatever you will try to change the IP, what you need to do is you need

04:41.130 --> 04:43.550
to also add it to the local host.

04:43.590 --> 04:46.740
So allow it host so you can have a hint here.

04:46.740 --> 04:49.680
So if we go to the settings here and then we have allowed.

04:49.710 --> 04:55.770
Host what I can do is I can add my IP either I can refresh it here.

04:57.890 --> 04:59.660
And I still have that running there.

04:59.660 --> 05:06.890
So what I will do is I will just make some changes so the this will be refreshed.

05:07.430 --> 05:13.760
I can come back here and then I need to restart the application.

05:21.500 --> 05:23.600
And then I can scan it again.

05:27.530 --> 05:29.840
And now I can see the list of movie there.

05:29.840 --> 05:37.220
If I go here, I don't see any error with a network error here because on my mobile I have a list of

05:37.220 --> 05:37.910
movies there.

05:37.910 --> 05:46.100
So what I can do is I can grab from here and I can replace with this IP instead of 127 and whatever.

05:46.100 --> 05:47.390
We use that here.

05:47.390 --> 05:55.190
So I have another place where I can use it and I can place it here and everything will work on all devices.
