Connecting Expo Built Mobile Apps to Localhost Deployed APIs
When connecting an iOS or Android app built using Expo to your data endpoints hosted on your localhost, you might hit a couple of roadblocks in terms of connectivity. This article covers ways to fix that issue in the subsections below.
Talking about the obvious, you need to make sure you are connected to the same Wi-Fi on both the device and your machine, so that 192.168 means the same thing.
If you are using “localhost” in your URLs, that could be confusing for your device. Use the exact IPv4 Address instead (something like 192.168.0.3, and not 127.0.0.1 or localhost). You can get that by running ipconfig and get your machine’s IP. You should also make sure your API can be called using that IP address, and it is not bound to “localhost” when you hosted it on your machine.
Are Ports Open?
You also need to check that the ports hosting your APIs are open on your machine to accept traffic from your device with your network, which otherwise would lead to a timeout error (“TIMEOUT_ERROR”) on your device.
Read more here: How To Open Firewall Ports In Windows 10 | Tom’s Hardware.
Also, if in your code you are using HTTPS, and your SSL is not set up properly, you will also get the same vague “Network Error” when trying to call the API. In this case, you should fix the local SSL problem on your machine, or go back to HTTP (THIS IS FOR LOCAL TESTING ONLY AND SHOULD NOT BE USED FOR HIGHER ENVIRONMENTS).
Feel free to check our scaffolds too. As far as the code is concerned, we have sorted out many of these issues. You will be up and running on day 1 and can focus on your business functions instead of foundations. Using our Identity, Payment, and Scaffolds will accelerate your delivery speed by months.
- React Web App (technologyleads.io)
- .Net 5.0 API Scaffold (technologyleads.io)
- React Native Mobile Scaffolds are on the way!
Credit: Source link