我嘗試使用我的后端 API 調整除錯 Angular 前端,但失敗了。我使用 VS2022 在埠 http://localhost:55278 上作業的后端我在控制臺中使用代理啟動 Angular
ng serve --open --proxy-config proxy.conf.json
我的 proxy.conf.json 是
{
"/api": {
"target": "http://localhost:55278",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
如果沒有 VS 除錯器,如果我啟動站點 http://localhost:4200/,我可以看到我的站點
比我為 VS Code 準備 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 Code 中按 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 開發的新手,不明白出了什么問題?
uj5u.com熱心網友回復:
您的 launch.json 似乎存在配置錯誤
嘗試url像在“啟動本地主機”中那樣添加屬性。
例如:
{
// 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}"
}
]
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/525664.html
上一篇:無法將psql插入本地轉發的dockerpostgres影像埠
下一篇:查找特定范圍內的素數
