关键词搜索

源码搜索 ×
×

使用Visual Studio Code调试运行在SAP云平台上处于运行状态的nodejs应用

发布2020-12-26浏览541次

详情内容

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里调试了:

    相关技术文章

    点击QQ咨询
    开通会员
    返回顶部
    ×
    微信扫码支付
    微信扫码支付
    确定支付下载
    请使用微信描二维码支付
    ×

    提示信息

    ×

    选择支付方式

    • 微信支付
    • 支付宝付款
    确定支付下载