Skip to content

body parser before proxy request #791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nguyenxuantuong opened this issue Mar 11, 2015 · 1 comment
Open

body parser before proxy request #791

nguyenxuantuong opened this issue Mar 11, 2015 · 1 comment

Comments

@nguyenxuantuong
Copy link

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.

matibek added a commit to matibek/node-http-proxy that referenced this issue Jun 23, 2016
Support for bodyparser.json and bodyparser.urlencoded.

Fixes http-party#955 http-party#843 http-party#791
jcrugzz pushed a commit that referenced this issue Aug 11, 2016
Support for bodyparser.json and bodyparser.urlencoded.

Fixes #955 #843 #791
@lchenay
Copy link

lchenay commented Apr 17, 2019

Please see : https://github.com/nodejitsu/node-http-proxy/blob/master/examples/middleware/bodyDecoder-middleware.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants