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

Nat*_*ael 4 port node.js visual-studio-code serverless serverless-framework-offline

我有两个无服务器脱机“服务器”,它们需要同时在本地运行。

因此,我需要更改其中一台服务器的端口。

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

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

小智 17

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

       }

   ]

}
Run Code Online (Sandbox Code Playgroud)

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

如果在Linux上,您的调试脚本将是:

// package.json
....
"scripts": {
    "debug": "export SLS_DEBUG=* && node --inspect /usr/local/bin/serverless offline -s dev"
  }
Run Code Online (Sandbox Code Playgroud)


Nat*_*ael 5

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

custom:
    serverless-offline:   ## add this two lines
        port: 4000        ## bellow "custom:" line
Run Code Online (Sandbox Code Playgroud)

  • 这如何解决问题?您不需要添加`launch.json`文件? (3认同)