http-proxy-middleware icon indicating copy to clipboard operation
http-proxy-middleware copied to clipboard

[HPM] Proxy error: ECONNREFUSED

Open jchayan opened this issue 11 years ago • 2 comments

Hi, I am serving a web application with gulp.js in port 3000, and a php backend application served in port 8000.

I am trying to use http-proxy-middleware in my gulp serve task in order to defer any calls from localhost:3000/api to my api endpoint at: localhost:8000/api. I have used it as follows:

proxyMiddleware('/api', { target: 'http://localhost:8000' });

For instance if I try to POST to api/authenticate, nodejs gives me in the console: [HPM] Proxy error: ECONNREFUSED localhost:8000/api/authenticate

So what I can see here is that it's actually trying to proxy it, but returns this unexpected error. Inspecting the network response I get:

Error occured while trying to proxy to: localhost:3000/api/authenticate

I don't know if this problem is related to myself using this module in an incorrect manner, any help would be very appreciated. Thanks in advance.

jchayan avatar Sep 06 '15 21:09 jchayan

It was a problem with the artisan server, had to run it this way:

php artisan serve --host 0.0.0.0

jchayan avatar Sep 06 '15 22:09 jchayan

The following also worked for me:

php artisan serve --host 127.0.0.1

awdyer avatar Apr 14 '16 22:04 awdyer