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

拥有回忆 提交于 2019-12-07 07:30:46

问题


I have two Serverless Offline "servers" which I need to run locally at same time.

So I need to change the port of one of the servers.

I run a server using Visual Studio Code debugger. The configs of the servers are in launch.json files.

How can I change the port of a Serverless Offline application so that I can run it in parallel with another Serverless Offline application using VS Code debugger?


回答1:


If you are using windows, update the vscode launch.json and package.json as below :

// 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"
  }

If on linux your debug script will be:

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



回答2:


Solved by adding the following lines to the serverless.yml file:

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


来源:https://stackoverflow.com/questions/51032833/how-to-debug-serverless-offline-in-visual-studio-code-using-another-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!