In my React Native app I have a request that looks like this:
axios.post(`http://${ipAddress}:3001/api/v1/customers/orders/create`, payload)
I am 100% certain that this route exists on the node server running on my laptop, and ipAddress
is the IP address for my laptop. The request even works in Postman and I get a response on the server. However, each time I try and make this request in RN the server doesn’t handle anything and I get the following error in RN:
", "_responseType": "", "_sent": true, "_subscriptions": [], "_timedOut": false, "_trackingName": "unknown", "_url": "http://myIP/api/v1/customers/orders/create", "readyState": 4, "responseHeaders": {"Access-Control-Allow-Origin": "*", "Connection": "keep-alive", "Content-Length": "170", "Content-Security-Policy": "default-src 'none'", "Content-Type": "text/html; charset=utf-8", "Date": "Sun, 10 Sep 2023 16:16:29 GMT", "Keep-Alive": "timeout=5", "X-Content-Type-Options": "nosniff", "X-Powered-By": "Express"}, "responseURL": "http://myIP:3001/api/v1/customers/orders/create", "status": 404, "timeout": 0, "upload": {}, "withCredentials": true}, "status": 404, "statusText": undefined}
Does anyone know what could be happening? I get that it says the route doesn’t exist, but it does which sort of makes that error message unhelpful.
2
Answers
you have to connect same router when testing your react native app. if you using physical device when testing your app instead of emulator there are some possibilities to have this error
you didn’t mention about your other routes working or not, if any route not working then,
at the end of all your routes for debugging, just to see if you are missing any specific method or url in the request.
this would give you what you are really missing.