Within my Expo React Native application, I am encountering issues with fetching data from my Ruby on Rails API due to restrictions on http connections.
I have explored various solutions that involve modifying the AndroidManifest.xml
in Android and Info.plist
in iOS, but since I prefer to work within Expo without ejecting, these options are not viable for me. I attempted changing the host from localhost
to 127.0.0.1
, 10.0.2.2
, and even my machine's IP address, but unfortunately none of these changes were successful. Despite checking the documentation on configuration with app.json and networking, I could not find any information on configuring App Transport Security within Expo. My current setup involves using Expo on android 9.0 Pie.
fetch(`http://localhost:3000/api/v1/trainers`, {
headers: {
Accept: 'application/json',
"Content-Type": "application/json"
},
}).then(res => res.json())
.catch(err => console.log(err));
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (420454d9-7271-44d5-b…-3a968d130699:48065)
at XMLHttpRequest.dispatchEvent (420454d9-7271-44d5-b…-3a968d130699:53513)
at XMLHttpRequest.setReadyState (420454d9-7271-44d5-b…-3a968d130699:52368)
at XMLHttpRequest.__didCompleteResponse (420454d9-7271-44d5-b…-3a968d130699:52195)
at 420454d9-7271-44d5-b…-3a968d130699:52305
at RCTDeviceEventEmitter.emit (420454d9-7271-44d5-b…-3a968d130699:22482)
at MessageQueue.__callFunction (420454d9-7271-44d5-b…-3a968d130699:22097)
at 420454d9-7271-44d5-b…-3a968d130699:21854
at MessageQueue.__guard (420454d9-7271-44d5-b…-3a968d130699:22051)
at MessageQueue.callFunctionReturnFlushedQueue (420454d9-7271-44d5-b…-3a968d130699:21853)