2

In a react app, one creates a setupProxy.js file and puts the following in it:

const proxy = require('http-proxy-middleware');
module.exports = function(app) {
    app.use(proxy('/api/*', 
        { target: 'http://localhost:5000/' }
    ));
}

But when I do the same thing and put this same file in a react native directory, the proxy doesn't work and I get network error from the client side. How does one setup a proxy in react native to connect with the server?

--- edit ---

I tried doing the following:

const endpointMiddleware = createEndpointMiddleware({
    apis: {
        default: {
            apiUrl: 'localhost:5000/api/*',
        },
    },
});


const middlewares = [reduxThunk, endpointMiddleware, apiMiddleware];
const store = createStore(reducers, {}, applyMiddleware(...middlewares));

But this hasn't worked.

zengod
  • 1,114
  • 13
  • 26

1 Answers1

-1

If you are using redux as your state manager you can use redux-api-middleware endpoint package. It worked for me.

Mantas Giniūnas
  • 677
  • 4
  • 11
  • Did you by any chance use axios and redux thunk? If so, can you show an example of how to set this proxy up for target localhost:5000 and /api/* path? – zengod Jan 15 '20 at 21:48
  • also, does the apiUrl property work with wildcards, i.e., *'s? – zengod Jan 15 '20 at 21:51