如何解决如何从React应用访问PCF中的VCAP_SERVICES?
我在PCF上托管了一个react应用,并绑定了凭据服务。
推荐的访问凭据的方法是使用process.env.VCAP_SERVICES。
如果我在应用程序内部使用它,则该值将返回为“未定义”。
我应该在.env文件还是manifest.yml文件中使用它?如果可以,怎么办?
另一个推荐的解决方案是使用cfenv程序包,但使用它时出现以下错误:
index.js:117 Uncaught TypeError: Arguments to path.join must be strings
at index.js:117
at Array.filter (<anonymous>)
at filter (index.js:287)
at Object.push../node_modules/path-browserify/index.js.exports.join (index.js:115)
at getPortsFile (index.js:62)
at Object.<anonymous> (index.js:13)
at Object../node_modules/ports/index.js (index.js:65)
at __webpack_require__ (bootstrap:784)
at fn (bootstrap:150)
at Object.<anonymous> (cfenv.js:13)
at Object../node_modules/cfenv/lib/cfenv.js (cfenv.js:314)
at __webpack_require__ (bootstrap:784)
at fn (bootstrap:150)
解决方法
一种方法是使用npm
vcap_services
安装:
npm install vcap_services --save
用法:
var vcapServices = require('vcap_services');
var credentials = vcapServices.findCredentials({ service: 'personality_insights' });
console.log(credentials);
更多详细信息here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。