简体   繁体   English

在SAP Cloud Foundry上远程调试node.js应用程序

[英]Remote Debugging a node.js application on SAP Cloud Foundry

We have hosted several node.js express services on SAP Cloud Foundry. 我们已经在SAP Cloud Foundry上托管了多个node.js Express服务。 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? 您如何远程调试SAP Cloud Foundry上托管的node.js应用程序(我们自己的)?
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. 在我们的案例中,我们有一个快递服务,该服务使用SAP Cloud SDK(v1.6.1)从SAP Cloud和OnPremise提供各种数据。

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. 首先,您需要在manifest.yml中修改应用程序的启动command ,以便能够附加调试器。 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: 在此示例中,我使用的是TypeScript,如果您使用的是普通JS,则可能看起来像这样:

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: 接下来,为了能够将调试器连接到检查器,您将需要打开一个到应用程序的ssh隧道,如下所示:

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). 这会将本地计算机的端口9229隧道传输到运行应用程序的容器上的端口9229(9229是检查器运行的默认端口)。

Finally, (and I'm assuming you use VS code here) you need to start your debugger. 最后,(我假设您在这里使用VS代码)您需要启动调试器。 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). 这种方法的缺点是(与调试Java应用程序相比),现在可以将其附加到正在运行的应用程序,因为您将需要以--inspect开始(默认情况下,您可能不想这样做)生产性应用)。 I have not found a solution for this yet. 我还没有找到解决方案。 So you might wanna have a separate deployment in case you're already running productively. 因此,如果您已经在高效运行,则可能需要单独部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM