http-proxy-middleware: [HPM] Error occurred while trying to proxy request
Expected behavior
make proxy request
Actual behavior
make proxy request unstable
Setup
- http-proxy-middleware: 0.17.1
- server: webpack -dev-server: 2.3.0
proxy middleware configuration
https://gist.github.com/djleonskennedy/e0521313bc6229d32b006e6d236c4ea3
server mounting
https://webpack.github.io/docs/webpack-dev-server.html#proxy
Hello this issue more about clarification, i have regular proxy to redirect requests to avoid CORS however also we need to be connected to customer VPN, and sometimes we have proxy worked and sometimes we have next
[HPM] Error occurred while trying to proxy request /login from localhost:4200 to <TARGET> (ETIMEDOUT) (https://nodejs.org/api/errors.html#errors_common_system_errors)
but without proxy TARGET endpoint works well always so we’ve decided that it can be problem with proxying some, could you please clarify about it?
Might i need to add some configuration?
Thank you
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 66
- Comments: 49 (4 by maintainers)
I get the error ([HPM] Error occurred while trying to proxy request /api/v1/xxx from localhost:3000 to http://xxx.com (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)) when I post a body. Solved it by remove the express body-parser middleware before HPM. Mybe help for someone.
In my case I add a header in the client(proxy), then solves it
may this will help you
use ip replace “localhost” . i am success,you can try
The
body-parserconsume the http request body stream before theHPMread it.body-parseris optional forexpress. If your app need it, place it afterHPM.Try this:
Replace
localhostwith[::1]Old config:
New config:
Works for me!
For me I fixed it by switching
localhostto127.0.0.1and it was happening locally as well as on Circle-CI. On CI I couldn’t make [::1] work but it’s maybe because of the vm I was using.I tried https://github.com/chimurai/http-proxy-middleware/issues/171#issuecomment-308690015, modified the example to:
Then hit http://localhost:3000 in my browser. It proxies the request perfectly fine.
With webpack 4.x, I have:
But I keep getting
In my terminal, or
In my browser. Not sure what the difference is 😦
Edit: Ok, I realized I’m dumb. I’m running webpack-dev-server in a docker/kubernetes container, which means I don’t want localhost nor port 8080. I need to use the internal hostname and port #. e.g.
For anyone running into this issue with Next.js you should be able to disable body-parser by adding
bodyParser: falseto the route config. E.g:For me, adding:
changeOrigin: truefixed the proxying for me. My origin just kills the connection if the hostname is incorrect.Don’t see anything unusual in your configuration. Understand your
<TARGET>is masked in the example. Can you provide an anonymized<TARGET>example? Since you can have many variations fortarget.Wondering if webpack-dev-server might cause the issue…
Can you try out a simplified setup with just
express+http-proxy-middlewareand see if the issue persists?https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md#express
I’m having the same issue while with the following config for Webpack dev server :
From what I’ve understood in the above comments, the solution is to remove body parser middleware, but I have no idea how to do that in Webpack config.
Anyone cool help me with that ? Thank you 😄
I got this error because I forgot the schema (http:// or https://) in front of the proxy target address. Maybe someone finds that helpful.
All the suggestions here are saying to remove body parser middleware if you don’t need it, but what if you do need it because your application is posting request bodies?
What’s the actual cause of this issue? I’m using https://www.npmjs.com/package/koa rather than Express with https://www.npmjs.com/package/koa-bodyparser to parse bodies.
Any workarounds I can try?
Could someone please elaborate on why removing body parser fix the error? I don’t see why the body parser is resetting the connection?
In my case: My target server is a java server, but I have a php server running on the same 9000 port. They do not conflict when launching because one is ipv4 and another is ipv6.
So, the following three solutions may work:
::1 localhostI didn’t use anything like bodyParser.json(), basically I’m using HPM and then send static files I read that it was included automatically with express 4? And I still get this error from time to time. Here’s my code:
I’ve tried different options but still no luck. Just couldn’t figure out how to disable body parser.
@chimurai We’ve solved with using
nginxlocalhost:4200 (angular CLI) -> http-proxy-middleware -> ngnix -> (vpn)