skip to Main Content

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


  1. 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,

    1. check your PC and mobile connected to same network
    2. check your PC wifi settings are in public network profile of private network profile sometimes I got couldn’t discoverable error when I’m in public network profile
    3. check your firewall blocking request or not.
    Login or Signup to reply.
  2. at the end of all your routes for debugging, just to see if you are missing any specific method or url in the request.

    app.get('*', function(req, res){
        console.error(" 404 page - ",req.url,req.method, req.body);
        res.send(JSON.stringify({status:0,message:"Invalid link",url:req.url,method:req.method,requestBody:req.body}));
    });
    
    app.post('*', function(req, res){
        console.error(" 404 page - ",req.url,req.method, req.body);
        res.send(JSON.stringify({status:0,message:"Invalid link",url:req.url,method:req.method,requestBody:req.body}));
    });
    

    this would give you what you are really missing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search