http-proxy-middleware icon indicating copy to clipboard operation
http-proxy-middleware copied to clipboard

404 errror instead of 302 response

Open dantiel opened this issue 7 years ago • 3 comments
trafficstars

Expected behavior

Correctly forward server response, when server responds with 302 Moved Temporarily

Actual behavior

Finalhandler created error response 404 Not Found "Cannot PATCH /externaj/path/to/api/other/resource". The original response is swallowed.

Setup

  • http-proxy-middleware: 0.18.0
  • server: webpack-dev-server

proxy middleware configuration

var apiProxy = proxy('/api', {
  target: 'http://localhost',
  pathRewrite: {
    '^/api': '/external/path/to/api'
  },
});

server mounting

var app = express();

app.use(apiProxy);
app.listen(3000);

Workaround

rewriting the response leads to the desired result

  onProxyRes(proxyRes, req, res) {
    if (302 === proxyRes.statusCode) {
      proxyRes.statusCode = 200;
    }
  }

dantiel avatar Aug 20 '18 02:08 dantiel

I am also having the same error, a 204 status code been returned from the proxied server is been converted into a 502 status code.

krvajal avatar Aug 21 '18 14:08 krvajal

The underlying http-proxy offers options such as: protocolRewrite autoRewrite hostRewrite...

Did you try those?

Would be nice if you can reproduce with just http-proxy. (with the underlying library)

chimurai avatar Aug 21 '18 17:08 chimurai

AFK right now. Will give it a shoot later on and post an example here.

krvajal avatar Aug 21 '18 18:08 krvajal