我有两台无服务器离线“服务器”,我需要同时在本地运行。
所以我需要更改其中一个服务器的端口。
我使用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