Okay.
In this video I will be talking about fetching data from the localhost and I will show you why that
might be a problem using our current setup.
So what we have so far is we are using our localhost.
So what will happen?
I will do expo start here.
So we have an expo opened here and normally I run it on simulator and emulator.
So simulator and emulator can easily communicate with our API that I have here.
So we have that running on the localhost.
So what is happening now?
If I will try to open this application on my phone, you will be able to see that actually on the screen.
I just scan the barcode here and you can see here this is building JavaScript bundle for me.
That have been finished and I have my application opened in my mobile, but I don't see a list of movies.
So why this is happening?
If I go here, you can see here network request failed and we can't actually get the request here because
my mobile, despite the fact it is on the same network as my computer here they cannot communicate with
this localhost API.
So what will be our solution?
Basically what we can do is we can tell this to run on a specific IP.
So if you don't provide any arguments like a run server, it will run on 127 001.
So our solution will be to get our IP, local IP and then use that IP for run the server so I can open
the terminal here and I can type in Ipconfig and then get if.
Address like this and then an zero.
So if I will do it this this is my local IP.
If you want to do it on the windows, it's a ipconfig like this.
And then you will be able to see the same thing in the IP version four address.
So if we have that IP handy for us, then we can use it.
But I will also show you another thing what we can do.
Remember, we have 192 160 815.
You will have something similar, but not the same as I have it here.
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
to find out you already have it here.
So that's your local IP.
And depending on the number of devices in your network, you might have like 130 or something like that.
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,
if I want to run this from here, I would normally do Python3 Manage.py run server and then I can run
the server normally.
But if you would like to run it on different IP, what you can do is you can use the IP and then port.
So then you will run the server on this IP with that port.
But we don't want to do it every single time.
We will open our PyCharm so we can also do here, edit configuration and then run server and then we
can pass another parameter here and then 8000 por.
So if I will apply this, if I will run it now.
I will stop the previous one and rerun it again.
You can see I have a new my local app here and that is Django is running on.
So we have a new URL.
So if I will go back to my code and here I'm fetching a list of movies.
So that was the previous.
Now I will use my own IP here, so I will save it here.
I think I need to close it and run it again.
So I will scan the code and I'm building a new application now.
This has been finished.
And if I go here, I still have a problem here.
So why this is happening?
But now it's not.
It's a different error.
So we have unrecognized token.
If I go here, you can see this invalid http host header.
So what is happening now is whatever you will try to change the IP, what you need to do is you need
to also add it to the local host.
So allow it host so you can have a hint here.
So if we go to the settings here and then we have allowed.
Host what I can do is I can add my IP either I can refresh it here.
And I still have that running there.
So what I will do is I will just make some changes so the this will be refreshed.
I can come back here and then I need to restart the application.
And then I can scan it again.
And now I can see the list of movie there.
If I go here, I don't see any error with a network error here because on my mobile I have a list of
movies there.
So what I can do is I can grab from here and I can replace with this IP instead of 127 and whatever.
We use that here.
So I have another place where I can use it and I can place it here and everything will work on all devices.