-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Adding body-parser-midddleware breaks proxy #363
Comments
Hi @ashleahhill, Thanks a lot for letting me know about this. I'd rather fix it if possible. I guess that there's some "interaction" with middlewares that you're using. I don't know if it's possible, but maybe you can try mounting JSON Server's middlewares on another path: server.use('/api', middlewares)
server.use('/api', router) If it doesn't work, how can I reproduce the issue with http-proxy-middleware? Do you have some simple code that fails with this version? |
Hi, @typicode , Sorry for the delay. Is there an error in your example? Did you mean something like this?
The setup for the proxy isn't suuuuper straightforward
Since we are already only putting the proxy middleware on paths that aren't served by JSON Server, I don't think that that solution will work. I vaguely remember that express applies middleware in the order they are received, so I'll try adding the proxy config before the JSON Server middleware and report back. |
Tried it. Body Parser still applies to every POST application/json request. I could add a layer that checks every request and, if its not a path configured to be proxied to the real API, proxy it to the JSON Server instance. But I'm not sure if that's the approach I want to take. |
Hi @ashleahhill Try restreaming the parsed body: |
I would suggest sticking with the previous version. I may simply remove And thank you for the detailed steps to reproduce. |
Hi @ashleahhill, I've published If you want, you can give it a try using Feedback is welcome :) |
Closing it since |
Our application uses json-server as a module to fill in the holes in an existing API. As a result, we rely pretty heavily on proxy functionality provided with http-proxy-middleware.
Unfortunately, a recent update to json-server has broken application/json POST requests through our proxy because adding body-body parser as top-level middleware in #338 affects the request sent through the proxy.
After encountering the issue and evaluating how our application has grown and what it needs, I've realized that it probably no longer fits the intended use json-server very well. However, for the benefit of others that are using jsons-server as a module, you may want to bump the version number with this added feature.
The text was updated successfully, but these errors were encountered: