简体   繁体   English

nconf没有从heroku上的文件加载

[英]nconf not loading from file on heroku

I have switched over from using dotcloud to heroku. 我已经从使用dotcloud切换到了heroku。 I am using nconf for my configuration. 我正在使用nconf进行配置。 I have it setup that it first grabs from the environment variables, and if not there, then it grabs from the config.json file. 我设置它首先从环境变量中获取,如果没有,那么它从config.json文件中获取。 On localhost this is working fine. 在localhost上这很好用。 For my build number, I store it in the config file, not in the environment variable, so that I can set it on push and then not have to change the environment. 对于我的内部版本号,我将它存储在配置文件中,而不是存储在环境变量中,以便我可以在推送时设置它,然后不必更改环境。

app.coffee app.coffee

nconf.argv().env().file file: "./config.json"

config.json config.json

{
    "APP_BUILD_NUMBER": "1.0.0"
}

If i run this locally or on dotcloud, nconf correctly passes 1.0.0 if I do 如果我在本地或在dotcloud上运行,如果我这样做,nconf正确传递1.0.0

nconf.get("APP_BUILD_NUMBER")

but, on heroku, it returns undefined. 但是,在heroku上,它返回undefined。 If I do set it in the environment variables, then it does work. 如果我在环境变量中设置它,那么它确实有效。 I am wondering what I am doing wrong. 我想知道我做错了什么。

Try removing the './' portion of the path: 尝试删除路径的“./”部分:

nconf.argv().env().file file: "config.json"

If that doesn't work, try 如果这不起作用,请尝试

nconf.argv().env().file file: __dirname + "/config.json"

I would recommend running heroku run bash then entering the Node REPL and trying multiple paths until you figure out what is different. 我建议运行heroku run bash然后输入Node REPL并尝试多个路径,直到找出不同的东西。 Making a change and then waiting for a push is too tedious a debug cycle. 进行更改然后等待推送是一个繁琐的调试周期。 I suspect your issue is around the path, or perhaps not unsetting the environment variable. 我怀疑你的问题是在路径周围,或者可能没有取消环境变量。

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

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