'http proxy middleware changes method From 'POST' to 'GET' on redirect
I'm using http-proxy-middleware in my recat app as follows
module.exports = function (app) {
app.use(
"/api",
createProxyMiddleware(filter, {
target: "https://example.com/",
secure: false,
changeOrigin: false,
logLevel: "debug",
followRedirects: true,
onProxyReq: (proxyReq, req, res) => {},
onProxyRes: (proxyRes, req, res) => {
const exchange = `[${req.method}] [${proxyRes.statusCode}] ${req.path} ->
${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path}`;
console.log(exchange);
},
onError: (err, req, res, target) => {
console.log(err);
},
})
);
};
I set followRedirects = true otherwise I get a 301 and then a 405 Method not allowed
now I get just the 405 I can see that the request is changed to a 'GET' request which is rejected by the server
this is my request
axios({
method: "POST",
data: data,
url: url,
}).then(r =>{
...
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
