让Heroku的配置变量在node.js中工作
I have a node app that has a line like this:
我有一个节点应用程序有这样的行:
var ip = process.env.IP || 'http://localhost';
I am using it with passport-facebook
node package to define the callback from Facebook authentication:
我使用passport-facebook节点包来定义来自Facebook身份验证的回调:
passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: ip + ":" + port + "/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
return done(null, profile);
});
}
));
It seems that Heroku doesn't know process.env.IP
so I went ahead and defined a config var
in Heroku:
似乎Heroku不知道process.env.IP所以我继续在Heroku中定义了一个config var:
heroku config:add process.env.IP=http://app.mydomain.com
Debugging the server I see that ip is not what I want but it's http://localhost
same as I defined as the fallback in the first line of code.
调试服务器我发现ip不是我想要的,但它的http:// localhost与我在第一行代码中定义的回退相同。
How do I get node to read the config var correctly from heroku ?
如何让节点从heroku正确读取配置变量?
1 个解决方案
#1
35
You want to use heroku config:set IP=http://app.mydomain.com
; it defines an environment variable called IP
, which you access in Node.js via process.env.IP
. See Setting up config vars for a deployed application for more information.
你想使用heroku配置:set IP = http://app.mydomain.com;它定义了一个名为IP的环境变量,您可以通过process.env.IP在Node.js中访问它。有关更多信息,请参阅为已部署的应用程序设置配置变量。
更多相关文章
- 在聚焦输入时,在iOS(和所有移动设备)上自定义滚动
- 使用bootstrap模式框的自定义选择框错误
- element.replaceWith在自定义指令的链接中仅在第一次调用时工作
- AngularJS:TypeError:无法读取未定义的属性'get'?
- 自定义ComboBox焦点不会切换到选择elem并且eventBubble不会停止
- javascript类定义与对象的性能
- 当函数在单独的PHP文件中定义时,调用JavaScript函数onclick按钮事
- Python NameError:全局名称“Form”没有定义pyqt
- django-modeltranslation:如何知道该值是否在给定语言中定义?