簡體   English   中英

如何使用另一個端口在 Visual Studio Code 中調試無服務器脫機?

[英]How to debug Serverless Offline in Visual Studio Code using another port?

我有兩個無服務器離線“服務器”,需要同時在本地運行。

所以我需要更改其中一台服務器的端口。

我使用 Visual Studio Code 調試器運行服務器。 服務器的配置在 launch.json 文件中。

如何更改無服務器離線應用程序的端口,以便可以使用 VS Code 調試器與另一個無服務器離線應用程序並行運行它?

如果您使用的是 windows,請更新 vscode launch.json 和 package.json 如下:

 // launch.json { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Debug Serverless", "cwd": "${workspaceFolder}", "runtimeExecutable": "npm", "runtimeArgs": [ "run", "debug" ], "outFiles": [ "${workspaceFolder}/handler.js" ], "port": 9229, "sourceMaps": true } ] }

 // package.json .... "scripts": { "debug": "SET SLS_DEBUG=* && node --inspect %USERPROFILE%\\AppData\\Roaming\\npm\\node_modules\\serverless\\bin\\serverless offline -s dev" }

如果在 linux 上,您的調試腳本將是:

// package.json
....
"scripts": {
    "debug": "export SLS_DEBUG=* && node --inspect /usr/local/bin/serverless offline -s dev"
  }

通過在 serverless.yml 文件中添加以下行來解決:

custom:
    serverless-offline:   ## add this two lines
        port: 4000        ## bellow "custom:" line

我使用的是 Linux 系統,這是我的 launch.json 和 package.json 文件的樣子。

啟動.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Debug Serverless",
            "cwd": "${workspaceFolder}",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run",
                "debug"
            ],
           "sourceMaps": true,
           "attachSimplePort": 9229
        }
    ]
}

包.json

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "debug": "node --inspect node_modules/serverless/bin/serverless offline -s dev"
  },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM