【问题标题】:Why can't Node-RED parse the VCAP_SERVICES environment in Bluemix?为什么 Node-RED 无法解析 Bluemix 中的 VCAP_SERVICES 环境?
【发布时间】:2015-05-06 17:27:10
【问题描述】:

我正在使用 Node-RED 并希望在 Bluemix VCAP_SERVICES 中进行解析,但我遇到了一个错误。我的代码是:

var services = context.global.VCAP_SERVICES;
var env_cloudint = services['CloudIntegration'][0].credentials;

但我收到此错误:

TypeError: Cannot read property 'CloudIntegration' of undefined

我的VCAP_SERVICES 中有 CloudIntegration。我是否需要在代码中添加任何额外内容才能利用 VCAP_SERVICES

【问题讨论】:

  • 您的错误表明“服务”本身未定义,而不是“服务”数组中的“CloudIntegration”项未定义

标签: ibm-cloud node-red


【解决方案1】:

默认情况下,环境变量不会添加到 Function 全局上下文对象中。要从 Node-RED 流访问 Bluemix VCAP_SERVICES 环境变量,您需要将其添加到 Function 节点的全局上下文中。

编辑 bluemix-settings.js 并向 functionGlobalContext 属性添加一个条目:

functionGlobalContext: { VCAP_SERVICES: JSON.parse(process.env.VCAP_SERVICES)}

然后重新部署您的应用。重新部署后,您可以在 Function 节点中以 context.global.VCAP_SERVICES 变量的形式访问 VCAP_SERVICES

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多