webpack
webpack copied to clipboard
Proxy doesn't work
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 ?
While trying ajax call, just do it on /api/test without localhost
我试了将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 Veryt thanks. It's working