http-proxy-middleware
http-proxy-middleware copied to clipboard
404 errror instead of 302 response
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;
}
}
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.
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)
AFK right now. Will give it a shoot later on and post an example here.