https://blogs.sap.comhttps://cdn.jxasp.com:9143/image/2020/11https://cdn.jxasp.com:9143/image/23/debugging-nodejs-application-in-vscode-running-on-sap-cloud-foundry
该nodejs应用的package.json:
{
"name": "debug-cloud",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "12.X"
},
"scripts": {
"start": "node --inspect index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
index.js:
const express = require('express')
const app = express()
app.get('/debug', function(req, res){
res.send("Debug endpoint called")
});
// Start server
app.listen(process.env.PORT || 8080, ()=>{})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
为了部署这个nodejs应用,需要一个Manifest.yml:
---
applications:
- name: debug-app
memory: 128M
random-route: true
buildpacks:
- nodejs_buildpack
- 1
- 2
- 3
- 4
- 5
- 6
- 7
使用命令行部署应用:
cf login #Perform you login to your cf account -- a demo account works as well
cf push #push your application
- 1
- 2
- 3
给CloudFoundry space启用ssh支持:
cf enable-ssh <app-name>
cf allow-space-ssh <space-name>
cf restage <app-name>
- 1
- 2
- 3
重启应用。
在Visual Studio Code里添加一个launch configuration:
{
"type": "node",
"request": "attach",
"name": "Attach cloud app ",
"address": "localhost",
"port": 9229,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/vcap/app"
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
将一个本地端口号绑定到nodejs应用上:
cf ssh <APP_NAME> -N -T -L 9229:127.0.0.1:9229
- 1
上述命令行将远端服务器的9229端口绑定到本地计算机的9229端口。
现在就可以开始在本地Visual Studio Code里调试了: