-
Notifications
You must be signed in to change notification settings - Fork 849
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
[HPM] Error occurred while trying to proxy request #171
Comments
Don't see anything unusual in your configuration. Wondering if webpack-dev-server might cause the issue... Can you try out a simplified setup with just https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md#express var express = require('express');
var proxy = require('http-proxy-middleware');
var app = express();
app.use(proxy("/api/auth/login", {
"target": "<TARGET>",
"secure": false,
"logLevel": "debug",
"pathRewrite": {
"^/api/auth": ""
},
"changeOrigin": true
}))
app.use(proxy("/api/auth/token/refresh", {
"target": "<TARGET>",
"secure": false,
"logLevel": "debug",
"pathRewrite": {
"^/api/auth": ""
},
"changeOrigin": true
}))
app.use(proxy("/api/loans", {
"target": "<TARGET>",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}))
app.use(proxy("/api/am", {
"target": "<TARGET>",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}))
app.use(proxy("/api/products", {
"target": "<TARGET>",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}))
app.listen(3000); |
@chimurai Thank you for answer, I'll try Thank you |
@chimurai problem with local environment |
Glad you've found an answer. |
@chimurai We've solved with using localhost:4200 (angular CLI) -> http-proxy-middleware -> ngnix -> (vpn) |
Yeah, we've not configured our application just with http-proxy-middleware It would be great to solve that problem just with one proxy :) |
Using multiple proxies is indeed not ideal. Can you provide an isolated example in which this issue is reproducible? I'll be happy to dive into it and see if it is an issue with HPM. |
You can go to our office and we'll show you. :)
Do you know any services where we can use vpn + proxy to provide an isolated example ? |
Not aware of any currently. Would be nice if you could spend some small effort to debug the issue. |
@chimurai According to my little investigation this is scenario with response delay from vpn connection. When i do request it goes throw proxy to
before using I've tried Regards |
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. |
In my case I add a header in the client(proxy), then solves it may this will help you
|
@wmzy I tried your solution (removed body-parser from the express app) and it worked, but I don't understand how the app is still working without |
The
|
use ip replace "localhost" . i am success,you can try |
@yuankui thank you for saving my life! |
I use Linux Ubuntu OS I have the same problem, in my node, vue project. |
Yup, body-parser was the cause for me! |
I got the same error using (vue.js, webpack-dev-server and http-proxy-middleware). proxy does not forward 'connection: keep-alive' option. i didn't investigate more why, but adding this option fixed my issue but thank you @yuankui |
Can someone please show me how to remove body-parser before using HPM? |
@kiennguyen1101 Look for a line that looks like |
I 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.
I've tried different options but still no luck. Just couldn't figure out how to disable body parser. |
Hi everyone, const proxy = require('http-proxy-middleware'); module.exports = function(app) { app.use(proxy('/ppe', app.use(proxy('/product', app.use(proxy('/client-roster', |
Try this: Replace Old config:
New config:
Works for me! |
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? |
I got this error because I forgot the schema (http:// or https://) in front of the proxy target address. Maybe someone finds that helpful. |
In my case: # lsof -i :9000 So, the following three solutions may work:
|
Could someone please elaborate on why removing body parser fix the error? I don't see why the body parser is resetting the connection? |
Replacing localhost to |
For me I fixed it by switching |
I'm having the same issue while with the following config for Webpack dev server : proxy: {
'*': {
target: 'https://laravel.test',
secure: false,
changeOrigin: true,
headers: { Connection: 'keep-alive' },
},
}, 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 😄 |
still have this problem,why ? |
I fixed the issue with this approach |
it's working |
removing the express body-parser middleware solved this issue for me. |
Replacing localhost to ::1 worked for me but why? Can anyone explain why this worked? @chan-dev This is because ping on Windows Vista and newer Windows uses IPv6 by default when available. ::1 is a shortened notation of IPv6 loopback address - equivalent of IPv4 loopback 127.0.0.1. The full notation of the abbreviated ::1 IPv6 address is 0000:0000:0000:0000:0000:0000:0000:0001. |
For me, adding: |
In my case changing version of wsl (windows subsystem for linux) helps. With version 2 error disappered |
OMG, thank you. It works. |
Having an issue similar to this one our solution was to allow the port with SELinux
https://blog.ijun.org/2014/11/selinux-allow-httpd-to-connect-to.html |
Thank you very much. It works. |
Tired many configurations, mine is quite unique. I use the hosts files to rewrite my domains from the typical 127.0.0.1, [::1], or localhost. I also have a build directory that will, more-or-less, generate a unique site based on the host path. I didn't need to change my host file but will include it as including ipv6 is becoming a necessity. While the initial 'target' will be replaced every time it seems it may need to be in the same IPV-Protocol as ... well speculation aside removing localhost, [::1], and keeping
__UPDATE
^ sounds silly works often |
i still have problem and i did everything but not working yet. and this is my configeration: my front port is 5000 and backend is 3000:80 devServer: {
|
For anyone running into this issue with Next.js you should be able to disable body-parser by adding export const config = {
api: {
externalResolver: true,
bodyParser: false,
},
}; |
I tried #171 (comment), modified the example to: var express = require('express');
var proxy = require('http-proxy-middleware');
var app = express();
app.use(proxy("/", {
target: 'http://127.0.0.1:8080/',
secure: false,
changeOrigin: true,
logLevel: "debug",
headers: { Connection: 'keep-alive' },
}
))
app.listen(3000); 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 me my localhost works but not the production |
If you use nestjs, you can disable body parser like this:
|
如果你是https协议,检查一下ssl证书是否过期 |
I am having same issue, anyone has any solution |
Expected behavior
make proxy request
Actual behavior
make proxy request unstable
Setup
proxy middleware configuration
server mounting
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
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
The text was updated successfully, but these errors were encountered: