Skip to content
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

[ERROR] - JSON POST BODY #455

Closed
prajwalkshetty opened this issue Jul 11, 2020 · 5 comments
Closed

[ERROR] - JSON POST BODY #455

prajwalkshetty opened this issue Jul 11, 2020 · 5 comments

Comments

@prajwalkshetty
Copy link

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

@prajwalkshetty prajwalkshetty changed the title JSON POST BODY [ERROR] - JSON POST BODY Jul 11, 2020
@chimurai
Copy link
Owner

Can't really do anything without minimal reproducible example.

@prajwalkshetty
Copy link
Author

@chimurai Sorry forgot to update here. I was able to figure out a fix for the issue from my side. Thanks for taking time to review the issue.

@chimurai
Copy link
Owner

Would be nice if you could share your solution for developers running into the same issue.

@geoangelotti
Copy link

I tried this from #320 (comment) 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
});

@prajwalkshetty
Copy link
Author

@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']

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

No branches or pull requests

3 participants