#1386·webpack

Proxy doesn't work

Author: KhivarCreated May 23, 2018Updated Mar 24, 2021

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 ?