App won't connect to backend

hey everyone so I was getting the Network Error before, and couldn’t figure out why it wasn’t working. I was able to use localhost and 127.0.0.1 (just learned they are the same thing) but as Mosh said, using localhost won’t work for android devices.

I then found a post in the React Native Developers discord channel where someone said that you can’t fetch from localhost because localhost is your own phone (if you try using localhost and running the app on your own physical iOS device, you’ll see that you still get the network error even though it works in the simulator). The same person who posted the above mentioned message then said that you need to use your computer’s LAN IP address. I had been using the IP address i found when I googled “what is my IP address” since I didn’t know there were different types/purposes.

After following the instructions on the following site (get your LAN IP address in MacOSX), and I have fixed the issue and can attest that using my LAN IP address allows my iOS simulator, iOS physical device, AND android simulator to successfully connect to my API.

As a reminder, you’ll have to use the LAN IP address in the baseURL in client.js in the client AND assetsBaseUrl in development.json in the API.

I hope this helps!

2 Likes