nx
nx copied to clipboard
react-native localhost fetching api not working
i use the steps for react native applications and try to use axios to make the petitions on my localhost server and always throws error connections and i using the ip of my computer
i'm using firebase functions emulator for the backend
this is how my functions looks

And this is de code that i use to make de petition in both applications

this is what i got and expected on the application with npx react-native init AwesomeProject

this is what i got with the application with nx

Computer: Mac mini M1 Mobile: Samsung Galaxy S10e Dependecies : @nrwl/next: 14.5.2 @nrwl/react-native: 14.5.2 @nrwl/workspace: 14.5.2 @react-native-firebase/app": ^15.2.0 @react-native-firebase/functions": ^15.2.0 axios": ^0.27.2
@victorrik i think it might be related to this issue: https://stackoverflow.com/questions/38418998/react-native-fetch-network-request-failed.
you need to add your api url to Info.plist and add request URL to NSExceptionDomains under NSAppTransportSecurity for ios, like:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>192.168.100.37</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
for android, you might need to change /android/app/src/main/res/xml/network_security_config.xml, and add the request URL to this config file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">192.168.100.37</domain>
</domain-config>
</network-security-config>
closing this issue since it is not a bug.