2

I used http-proxy-middle for proxying my api domain in order to bypass CORS issue. My code works in localhost, but when it is not working in my live domain.

My code is:

const proxy = require('http-proxy-middleware');
  app.use(
    '/api',
    proxy({
      target: ' mylivedomain.com',
      pathRewrite: {
        '^/api': '/',
      },
      changeOrigin: true,
      logLevel: 'debug',
      secure: false,
    }),
  );

I checked in the network tab, I got a status code: 302 when trying to GET or POST method. Does anyone have any ideas how to fix it?

Kevin
  • 45
  • 9
  • First to mention, the network traffic you saw in chrome network tab, is sent from browser side to your nodejs server. The `http-proxy-middleware` works inside your nodejs server, whose traffic cannot be seen in the network tab of your browser. – iplus26 May 26 '19 at 05:33
  • You may focus on digging the network connection between your nodejs server and the resource server you're trying to proxy to. For example, are you behind a company proxy, or the resource server need auth? – iplus26 May 26 '19 at 05:41

0 Answers0