Remote Debugging a node.js application on SAP Cloud Foundry

为君一笑 提交于 2019-12-23 03:42:37

问题


We have hosted several node.js express services on SAP Cloud Foundry. Since we can't get any further with this problem and maybe others are faced with this problem, here is the explicit question about this:
How can you remotely debug a node.js application (our own) hosted on SAP Cloud Foundry?
In our case, we have an express service that uses the SAP Cloud SDK (v1.6.1) to provide various data from SAP Cloud and OnPremise.


回答1:


I'm not sure whether this is the best approach, but it works for me, so here goes:

First, you need to adapt the start command of your app in the manifest.yml so that you're able to to attach your debugger. For example:

command: node --inspect --require ts-node/register src/index.ts

In this example I'm using TypeScript, if you're using plain JS, it would probably look something like this:

command: node --inspect src/index.js

Next, in order to be able to attach the debugger to the inspector, you will need to open an ssh tunnel to your app, like this:

cf ssh <APP_NAME> -N -T -L 9229:127.0.0.1:9229

This will tunnel port 9229 of your local machine to port 9229 on the container your app is running in (9229 is the default port the inspector runs on).

Finally, (and I'm assuming you use VS code here) you need to start your debugger. Here's the configuration I'm using for that:

{
  "type": "node",
  "request": "attach",
  "name": "Attach to Remote",
  "address": "localhost",
  "port": 9229,
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "/home/vcap/app"
}

The drawback of this approach is (compared to debugging a Java app) that there is now way to attach to a running application, because you will need to have started your with --inspect (which you probably will not want to do by default for a productive app). I have not found a solution for this yet. So you might wanna have a separate deployment in case you're already running productively.



来源:https://stackoverflow.com/questions/57183017/remote-debugging-a-node-js-application-on-sap-cloud-foundry

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