我尝试使用后端API调整调试Angular前端,但失败了。我的VS2022后端正在端口上工作http://localhost:55278我在控制台中使用代理启动Angular
ng serve --open --proxy-config proxy.conf.json
我的代理人conf.json是
{
"/api": {
"target": "http://localhost:55278",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
没有VS调试器,如果我启动站点,我可以看到我的站点http://localhost:4200/
然后我为VS代码准备launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch index.html",
"type": "firefox",
"request": "launch",
"reAttach": true,
"file": "${workspaceFolder}/index.html"
},
{
"name": "Launch localhost",
"type": "firefox",
"request": "launch",
"reAttach": true,
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}",
"timeout": 90000,
"tmpDir": "/some/folder/of/yours/with/write/perms",
"firefoxExecutable": "C:\Program Files\Mozilla Firefox\firefox.exe"
},
{
"name": "Attach",
"type": "firefox",
"request": "attach",
"pathMappings": [
{
"url": "webpack:///src/app/pages/admin/home",
"path": "${workspaceFolder}/src/app/pages/client/home"
},
{
"url": "webpack:///src/main.ts",
"path": "${workspaceFolder}/src/main.ts"
}
]
},
{
"name": "Launch WebExtension",
"type": "firefox",
"request": "launch",
"reAttach": true,
"addonPath": "${workspaceFolder}"
}
]
}
如果我在VS代码中按下Attach或Lanch,我会收到错误消息
[HPM] POST /api/auth/user/ -> http://localhost:55278
[HPM] Error occurred while trying to proxy request /api/auth/user/ from localhost:4200 to http://localhost:55278 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
我是Angular开发的新手,不明白哪里出了问题?
这似乎是您的launch.json 的配置错误
尝试添加CCD_ 1属性,就像您在";启动localhost";。
例如:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch index.html",
"type": "firefox",
"request": "launch",
"reAttach": true,
"url": "http://localhost:4200",
"file": "${workspaceFolder}/index.html"
},
{
"name": "Launch localhost",
"type": "firefox",
"request": "launch",
"reAttach": true,
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}",
"timeout": 90000,
"tmpDir": "/some/folder/of/yours/with/write/perms",
"firefoxExecutable": "C:\Program Files\Mozilla Firefox\firefox.exe"
},
{
"name": "Attach",
"type": "firefox",
"request": "attach",
"url": "http://localhost:4200",
"pathMappings": [
{
"url": "webpack:///src/app/pages/admin/home",
"path": "${workspaceFolder}/src/app/pages/client/home"
},
{
"url": "webpack:///src/main.ts",
"path": "${workspaceFolder}/src/main.ts"
}
]
},
{
"name": "Launch WebExtension",
"type": "firefox",
"request": "launch",
"reAttach": true,
"url": "http://localhost:4200",
"addonPath": "${workspaceFolder}"
}
]
}