node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

add extra information to proxyReq object

Open prasadtechnology opened this issue 6 years ago • 1 comments

Hi

Before sending request to target server i want to add user information to proxyReq object. Currently target server recieving undefined.

Here is the code snippet

apiProxy.on("proxyReq", function(proxyReq, req, res, options) { proxyReq.setHeader("Authorization", req.headers['Authorization']); **proxyReq.userInfo = {email: "vikranth"};** if (req.body) { let bodyData = JSON.stringify(req.body); proxyReq.setHeader("Content-Type", "application/json"); proxyReq.setHeader( "Content-Length", Buffer.byteLength(bodyData) ); proxyReq.write(bodyData); } });

prasadtechnology avatar Apr 03 '20 05:04 prasadtechnology

proxyReq.userInfo will never send anything to your server.

If you use with the express, req.body will empty if you do not have body-parser middleware

samuraitruong avatar Jun 09 '20 10:06 samuraitruong