question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ERROR] - JSON POST BODY

See original GitHub issue

Is this a question?

When using it with express server and trying to post json body, it seems like anything above 1KB since request fails. I tried using express.json() middle also body parser but it does not seem to go along smoothly with the proxy middleware. Any help regarding this issue would be helpful. Thanks in advance for the time.

this.app .use(this.parseRequestBody.bind(this)) .use(‘*’, apiProxy) .use(express.json()) .listen(proxyPort);

Is this a bug report?

Yes

Is this a feature request?

No

  • http-proxy-middleware: 1.0.4
  • http-proxy-middleware configuration { // This value is not used but this is mandatory. target: proxyPort.toString(), changeOrigin: true, followRedirects: true, preserveHeaderKeyCase: true, pathRewrite: this.rewritePath.bind(this), router: this.rewriteHost.bind(this), onError: function onError(err, _req, _res) { // TODO: In future expose it as a callback. }, onProxyReq: this.onProxyReq.bind(this) }
  • server: express
  • other relevant modules

(Paste the link to an example project and exact instructions to reproduce the issue.)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
geoangelotticommented, Jul 16, 2020

I tried this from https://github.com/chimurai/http-proxy-middleware/issues/320#issuecomment-600470764 and it worked for me.

You just need to reorder the middlewares; put bodyParser after all proxy middlewares and routes without proxy after bodyParser ex:

app.use('/proxy/routex', myProxy);
app.use('/proxy/routey', myProxy);

... //then, after all proxys
app.use(bodyParser.json());

//and now, all no proxy routes
app.use('/api', (req,res)=>{
//TODO
});

app.get('/api/test', (req,res)=>{
//TODO
});
0reactions
prajwalkshettycommented, Jul 16, 2020

@chimurai @geoangelotti Sorry for the delay in responding. Back i already had in that order even after that it was causing me issues, for me it was a specific issue of post body being greater than 1KB. For some reason something was adding a header i had to delete below headers before passing the request object to the proxy middleware and everything worked fine after that. delete req.headers[‘expect’] delete req.rawHeaders[‘expect’]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting error while POST request with JSON - Stack Overflow
When i am firing POST request i am expecting it to push the JSON content into the users object but instead of it...
Read more >
Error creating JSON data source with "POST Body" parameters
When creating a JSON data source using HTTP Client as Data Route and POST as HTTP Method, there are two ways of adding...
Read more >
HTTP status and error codes for JSON | Cloud Storage
HTTP status and error codes for JSON · 302—Found · 303—See Other · 304—Not Modified · 307—Temporary Redirect · 308—Resume Incomplete · 400—Bad...
Read more >
Error while parsing JSON Response in REST API Post call
I am using Outsystems 10 and trying to consume a REST API (single method). I have copied and pasted the REST Request and...
Read more >
Response codes - The REST API basics - Akeneo API
As JSON format is expected in all POST and PATCH requests, you will get this error response when your JSON body is malformed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found