-
Notifications
You must be signed in to change notification settings - Fork 854
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
Missing req.body #202
Comments
You'll need the |
Nice! Please close this. |
When I used the bodyParser, I was able to access the req.body in the onProxyReq function. But, then I remembered why I had commented out bodyParser in the first place. With the bodyParser in place, http-proxy-middleware doesnt work. I do see that in the example it is mentioned that body-parser will work... but, I dont see that happening. Here's the relevant part of the server code. ` app.use(apiProxy); PS: I actually dont want to modify the post body. I want to modify the request header based on the body content. |
The one difference I see between the example and my code is that I don't use routes in express. Is it mandatory to use routes to get bodyParser and http-proxy-middleware working together? |
I did see that @flackenstein has posted a solution at #61 which I guess was probably the predecessor to the example. But, in that example, the post body is converted from an object to a application/x-www-form-urlencoded type. I don't want that. I want to the body to be just proxied on untouched. |
Nevermind... I think I got the solution. @chimurai's post on #40 has an example that can do what I'm trying to do. if (req.body) {
let bodyData = JSON.stringify(req.body);
// incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json
proxyReq.setHeader('Content-Type','application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
// stream the content
proxyReq.write(bodyData);
} |
@chimurai what do you think about adding the last comment above to the docs? |
I love you !!! |
With reference to the recipe to manipulate the request object posted at https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/modify-post.md
onProxyReq
This is the request object I am sending from my client:
But, I am not seeing any body in the output. Here's the output I am seeing.
Console Log output
What am I doing wrong here?
The text was updated successfully, but these errors were encountered: