react-native-template
react-native-template copied to clipboard
Fix API requests to localhost on Android
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.