如何使用另一个端口在Visual Studio代码中调试无服务器脱机?

问题描述 投票:2回答:2

我有两台无服务器离线“服务器”,我需要同时在本地运行。

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

我使用Visual Studio Code调试器运行服务器。服务器的配置在launch.json文件中。

如何更改无服务器脱机应用程序的端口,以便我可以使用VS Code调试器与另一个无服务器脱机应用程序并行运行?

node.js visual-studio-code port serverless serverless-framework-offline
2个回答
8
投票

如果您使用的是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"
  }

2
投票

通过将以下行添加到serverless.yml文件来解决:

custom:
    serverless-offline:   ## add this two lines
        port: 4000        ## bellow "custom:" line
© www.soinside.com 2019 - 2024. All rights reserved.