【问题标题】:How to remotely live debug node.js app, while running on Azure App Service on Linux如何在 Linux 上的 Azure 应用服务上运行时远程实时调试 node.js 应用
【发布时间】:2020-12-23 21:15:55
【问题描述】:

我正在尝试远程调试在 Linux 上的 Azure 应用服务上运行的 node.js 应用。 VSCode 的 Azure Remote Debugging for Node.js 对我不起作用,所以我正在尝试通过使用 Azure CLI 的 create-remote-connection 命令打开的 SSH 会话来使用 remote debugging。

az webapp create-remote-connection –g [resource group] -n [app name] -p 9229

我的 launch.json 文件有

{
            "type": "node",
            "request": "attach",
            "name": "Attach to remote",
            "address": "127.0.0.1",
            "port": 9229,
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/home/site/wwwroot",

        }

接下来,我在我的机器上运行 SSH

ssh -L 9229:127.0.0.1:9229 root@127.0.0.1

但我不知道下一步该做什么。在 Linux 上的 Azure 应用服务上运行时,如何远程实时调试此应用?

【问题讨论】:

    标签: node.js azure visual-studio-code azure-web-app-service


    【解决方案1】:

    使用az webapp remote-connection create 命令打开与您的应用的远程连接。

    az webapp create-remote-connection –g [resource group] -n [app name]
    

    命令输出为您提供打开 SSH 会话所需的信息。

    Verifying if app is running....
    App is running. Trying to establish tunnel connection...
    Opening tunnel on port: 49288
    SSH is available { username: root, password: Docker! }
    

    使用上面输出中的端口启动本地 SSH 隧道。

    ssh -L  9221:127.0.0.1:9229 root@127.0.0.1 -p 49288
    

    这将启动一个 ssh 隧道会话,在该会话中,与本地计算机上端口 9221 的连接将被转发到在应用服务中运行的远程容器上的端口 9229。

    通过身份验证后,运行top 命令以获取您的节点应用程序的 pid。假设它是67。运行node inspect。

    node inspect -p 67
    

    使用 launch.json 中的配置运行 VSCode

    {
                "type": "node",
                "request": "attach",
                "name": "Attach to remote",
                "address": "127.0.0.1",
                "port": 9221,
                "localRoot": "${workspaceFolder}",
                "remoteRoot": "/home/site/wwwroot",
    
            },
    

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 2020-07-31
      • 2023-03-23
      相关资源
      最近更新 更多