question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't make requests to local API server

See original GitHub issue

Description

Can’t connect to an API server ran on my local machine from my android phone running my Expo app. The IP address of my machine on my local network is 192.168.1.14, so my app is served on the URL http://192.168.1.14:19000. My API server is on http://192.168.1.14:3000, and I can connect to it on my phone browser.

Expected Behavior

The fetch request to http://192.168.1.14:3000 should return the same data as the request through my browser.

Observed Behavior

I have to wait around 30 seconds of awaiting for a response, then I get this:

Possible Unhandled Promise Rejection (id: 0):
TypeError: Network request failed
onerror@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:13802:29
dispatchEvent@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:14702:39
setReadyState@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:16809:31
__didCompleteResponse@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:16665:27
http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:16760:50
emit@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:5278:40
__callFunction@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3517:47
http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3375:29
__guard@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3489:11
callFunctionReturnFlushedQueue@http://192.168.1.14:19001/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false:3374:19
callFunctionReturnFlushedQueue@[native code]

Environment

Please run these commands in the project folder and fill in their results:

  • npm ls react-native-scripts: react-native-scripts@0.0.30
  • npm ls react-native: react-native@0.44.2
  • npm ls expo: expo@17.0.0
  • node -v: v7.4.0
  • npm -v: 4.0.5
  • yarn --version: 0.24.5
  • watchman version: 4.7.0

Also specify:

  1. Operating system: Ubuntu 16.04
  2. Phone/emulator/simulator & version: Android 6.0.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
brentvatnecommented, Jun 5, 2017

hello! I think you may be mistaken and have made some error somewhere in your code. see https://github.com/brentvatne/crna-issue-241-example for a minimal example of what you describe in this issue, and notice that it works as expected. if that example doesn’t work for you then let me know!

1reaction
brentvatnecommented, Jun 26, 2018

you need to be able to access the server from your phone. if you can’t access it from a web browser you also can’t access it from an app

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't make requests to local API server · Issue #241 - GitHub
You could try this: Open "Node.js command prompt" and type ipconfig . From there, copy your IPv4-IP-address. ... That worked for me.
Read more >
Cannot connect to localhost API from Android app
You can not access a local api outside from that local device. 127.0.0.1 is the local address of its own. If you want...
Read more >
Unable to Consume Rest API from Local Server - OutSystems
A rest API can only be consumed if it has a valid public domain or public IP address so that it can be...
Read more >
Localhost api call not working - Just getting started - Postman
Hi, I am trying to interact to my back-end golang server which is running on port number 9000.I tried to connect by changing...
Read more >
Unable to access HTTP based Web Api from HTTPS based ...
You can have a try the wildcard value "*" to see if it works. this will allow requests from any origins. 50251-image.png. Thanks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found