webpack icon indicating copy to clipboard operation
webpack copied to clipboard

Proxy doesn't work

Open Khivar opened this issue 6 years ago • 3 comments

Hello,

My dev server is on localhost:8888 and my api server is on localhost:8889, here is my config :

    proxyTable: {
        '/api': {
            target: "http://localhost:8889",
            changeOrigin: true,
            pathRewrite: {
                '^/api': ''
            }
        },
    },

If i open http://localhost:8889/test directly in my browser it works and i get my json {"hello":"world"}

If i do an ajax call on http://localhost:8888/api/test, in the console log i get :

[HPM] Error occurred while trying to proxy request /test from localhost:8888 to http://localhost:8889 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)

So I get a connection refused error but I can access http://localhost:8889 just fine from the browser

In the browser the response has a 504 status with the payload :

Error occured while trying to proxy to: localhost:8888/test

It is strange since it states that it tried to proxy to localhost:8888 when it should be localhost:8889.

Any idea of what's going on ?

Khivar avatar May 23 '18 07:05 Khivar

While trying ajax call, just do it on /api/test without localhost

syniavskyi avatar Oct 14 '18 14:10 syniavskyi

我试了将localhost改成ip问题解决,同时服务端启动服务监听127.0.0.1的8889端口:http://127.0.0.1:8889。

I fix this problem by change localhost to 127.0.0.1, As the same time is the server side, listening 8889 on 127.0.0.1: http://127.0.0.1:8889

lyenrowe avatar Apr 10 '19 08:04 lyenrowe

@lyenrowe Veryt thanks. It's working

mikkame avatar Mar 24 '21 07:03 mikkame