body parser before proxy request
Created by: nguyenxuantuong
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.