在SAP Cloud Foundry上远程调试node.js应用程序 [英] Remote Debugging a node.js application on SAP Cloud Foundry

查看:110
本文介绍了在SAP Cloud Foundry上远程调试node.js应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在SAP Cloud Foundry上托管了多个node.js Express服务.由于我们无法进一步解决此问题,也许其他人可能会遇到

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.

推荐答案

我不确定这是否是最好的方法,但是它对我有用,所以去了:

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

首先,您需要在manifest.yml中修改应用程序的开始command,以便能够附加调试器.例如:

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

在此示例中,我使用的是TypeScript,如果您使用的是普通JS,它可能看起来像这样:

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

接下来,为了能够将调试器附加到检查器,您将需要打开一条通往应用程序的ssh隧道,如下所示:

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

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

最后,(我假设您在这里使用VS代码)您需要启动调试器.这是我正在使用的配置:

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"
}

此方法的缺点是(与调试Java应用程序相比),现在可以将其附加到正在运行的应用程序,因为您需要先从--inspect开始(您可能不想这样做)对于生产性应用,默认情况下).我还没有找到解决方案.因此,如果您已经在高效地运行,您可能想要进行单独的部署.

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.

这篇关于在SAP Cloud Foundry上远程调试node.js应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆