I want to proxy my POST request. What i get is 301 redirection instead of 307 whenever i am doing a post request.
Thats my webpack-dev-server config:
gulp.task("serve", ['webpack', 'copyIndex', 'dump', 'vendor'], function (callback) {
function restream(proxyReq, req, res, options) {
if (req.body) {
let bodyData = JSON.stringify(req.body);
// incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
proxyReq.setHeader('Content-Type','application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
// stream the content
proxyReq.write(bodyData);
}
}
var proxy = {
'localhost:8888/rest': {
target: {
host: 'my-app.pl',
protocol: 'https',
port: 80
},
changeOrigin: true,
secure: false,
logLevel: 'debug',
onProxyReq: restream
}
};
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
myConfig.proxy = proxy;
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
quiet: false,
noInfo: false,
contentBase: "./dist",
proxy: proxy,
stats: {
colors: true
}
}).listen(8888, "localhost", function (err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[webpack-dev-server]", "http://localhost:8888/webpack-dev-server/index.html");
});
});
I used this solution to restream parsed body, but req.body in restream function is always undefined, no matter if its GET request or POST with data.
GET requests are working fine. They are all proxied well.
Any ideas?
You can try the following configuration options and see if those will fix the redirect issues.
hostRewrite: rewrites the location hostname on (201/301/302/307/308) redirects.
autoRewrite: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.
protocolRewrite: rewrites the location protocol on (201/301/302/307/308) redirects to 'http' or 'https'. Default: null.
And how is the redirect issue related to restreaming?
Issue has gone stale; Closing issue.
Feel free to re-open.
Having the same problem, is there a solution?