Skip to content

body parser before proxy request #791

Open
@nguyenxuantuong

Description

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions