You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am wondering is there anyway to use body parse before proxy request. Here is my scenario:
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));
proxy.on('proxyReq', function(proxyReq, req, res, options) {
//Need to write custom logic to check for the parameter inside the body. -- so that it can add custom header or modify proxyReq body, etc...
//for example: var userId = req.param("userId") -> this one only available with bodyParser declared //before this one (see abover)
});
app.all(route, function(req, res){
//proxy request to target url
return proxy.web(req, res, { target: config.localUrl + "/api"}, function(e) {
return res.json(501, e.stack || e.error || e);
});
});
The web application at target also uses its own bodyParser. But it seems that because the body parser being used twice, no response arrived after proxy the request to target. I am wondering if there is any way to work around that issue? Thank.
The text was updated successfully, but these errors were encountered:
matibek
added a commit
to matibek/node-http-proxy
that referenced
this issue
Jun 23, 2016
I am wondering is there anyway to use body parse before proxy request. Here is my scenario:
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));
proxy.on('proxyReq', function(proxyReq, req, res, options) {
//Need to write custom logic to check for the parameter inside the body. -- so that it can add custom header or modify proxyReq body, etc...
//for example: var userId = req.param("userId") -> this one only available with bodyParser declared //before this one (see abover)
});
app.all(route, function(req, res){
//proxy request to target url
return proxy.web(req, res, { target: config.localUrl + "/api"}, function(e) {
return res.json(501, e.stack || e.error || e);
});
});
The web application at target also uses its own bodyParser. But it seems that because the body parser being used twice, no response arrived after proxy the request to target. I am wondering if there is any way to work around that issue? Thank.
The text was updated successfully, but these errors were encountered: