react-native-template icon indicating copy to clipboard operation
react-native-template copied to clipboard

Fix API requests to localhost on Android

Open isaiahgrey93 opened this issue 5 years ago • 0 comments

Finally was able to resolve an issue I've dealt with in several apps where on the Android platform, requests to localhost do not resolve despite adb reverse being called correctly. I was able to fix this issue by modify the environment variable while in dev mode (_DEV_ = true) by pointing at 10.0.2.2 instead of localhost :

if (__DEV__ && Platform.OS === 'android') {
  ENV.API_URL = API_URL.replace('localhost', '10.0.2.2');
}

We should add this to our default setup.

isaiahgrey93 avatar Sep 29 '20 17:09 isaiahgrey93