Javascript 为什么用于角度开发的本地代理配置不起作用?
我正在尝试用Angular开发一个应用程序。 我将Javascript 为什么用于角度开发的本地代理配置不起作用?,javascript,node.js,angular,typescript,proxy,Javascript,Node.js,Angular,Typescript,Proxy,我正在尝试用Angular开发一个应用程序。 我将package.json中的start命令设置为ngserve--proxyconfig proxyconfig.json,然后proxyconfig.json我进行了如下设置: { "/api": { "target": "http://localhost:1234", "secure": false, "changeOrigi
package.json
中的start命令设置为ngserve--proxyconfig proxyconfig.json
,然后proxyconfig.json
我进行了如下设置:
{
"/api": {
"target": "http://localhost:1234",
"secure": false,
"changeOrigin": true
},
"/auth": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true
}
}
但是,当我稍后尝试调用/api时
return this.http.get("/api/items.php").subscribe(...);
,我得到以下错误:
[HPM] Error occurred while trying to proxy request /api/items.php from localhost:4200 to http://localhost:1234 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
其中4200端口是Angular应用程序所在的位置。如果我转到http://localhost:1234/items.php
直接使用,效果很好
不知道我做错了什么