debugging 使用VS代码和Firefox进行Angular 调试->[HPM]尝试将请求/api/auth/user/从localhost:4200代理到

yizd12fk  于 2022-11-14  发布在  Angular
关注(0)|答案(1)|浏览(182)

我尝试使用我的后端API调整调试Angular前端,但失败。我的后端使用VS 2022在端口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代码准备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 开发的新手,不明白哪里出了问题?

6l7fqoea

6l7fqoea1#

似乎是launch.json的配置错误
尝试添加url属性,就像您刚才在“启动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}"
        }
    ]
}

相关问题