How to Setup Proxy Target in React Native with Nodejs?

Viewed 1325

Trying to configure proxy in react native with node to run axios calls.

Tried the following code in server/package.json

"proxy": {
    "/*": {
      "target": "http://localhost:5000/"
    }
  },
  "scripts": {
    "start": "node index.js",
    "server": "nodemon index.js",
    "client": "cd ../client && yarn ios",
    "dev": "concurrently \"yarn server\" \"yarn client\""
  }

server/authRouter.js

const authRouter = require('express').Router();
authRouter.get('/test', (req, res) => {
    res.send('proxy success');
  });

module.exports = authRouter;

server/index.js

const express = require('express');
const authRouter = require('./authRouter');
const app = express();
app.use('/auth', authRouter);
const PORT = process.env.PORT || 5000;
app.listen(PORT);

client/app.js

await axios.get('/auth/test');

When I run yarn dev and test an axios call, it logs the following error

 LOG      [Error: Network Error]

any help would be much appreciated.

1 Answers
Related