[英]environment variables in heroku
const firebase = require('firebase');
const devConfig = {
//config here
};
const prodConfig = {
//config here
};
export const firebaseInit = firebase.initializeApp(process.env.NODE_ENV == 'development' ? devConfig : prodConfig);
export const rootRef = firebase.database().ref();
i have this firebase config file. 我有这个firebase配置文件。
in my procfile i have: web: NODE_ENV=production node ./src/server/index.js
在我的procfile中,我有: web: NODE_ENV=production node ./src/server/index.js
in my webpack i have: 在我的webpack中,我有:
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV) || '"development"'
}
}),
and in my package.json i have: 在我的package.json中,我有:
"start": "node src/server/index.js",
"start:production": "NODE_ENV=production ./node_modules/.bin/webpack && node src/server/index.js",
"start:dev": "NODE_ENV=development ./node_modules/.bin/webpack && node src/server/index.js",
and in my heroku app settings i have gone and set NODE_ENV
as the key with production
as the value 在我的heroku应用程序设置中,我将NODE_ENV
设置为key,将production
为value
i have deployed the master code after pushing my code up. 在将代码向上推后,我已经部署了主代码。 yet when the app starts up it still logs up in my console as 'development mode'. 但是,当应用启动时,它仍然以“开发模式”登录到我的控制台。 what am i missing to start the app in production? 我缺少在生产中启动该应用程序的原因? i can do it locally just not on heroku 我可以在本地做到这一点,而不是在heroku上
Not sure if any of this fixes your issue, but hopefully it helps. 不知道这是否能解决您的问题,但希望对您有所帮助。
1) Could Heroku be picking up the "start" script before the Procfile which doesn't have "NODE_ENV=production" in it? 1)Heroku可以在Procfile中没有“ NODE_ENV = production”的代码前拾取“ start”脚本吗? I don't use a Procfile, I just rely on the start script, so not sure. 我不使用Procfile,我只是依靠启动脚本,所以不确定。
2) Does NODE_ENV=production definitely carry through after an && in start:production script call? 2)在start:production脚本调用&&之后,NODE_ENV = production是否肯定进行? It might be worth copying and pasting it to before the node script too, just to be sure. 可以肯定,值得将其复制并粘贴到节点脚本之前。
3) JSON.stringify will resolve an empty string as true so best to put || 3)JSON.stringify会将一个空字符串解析为true,因此最好将||放入 "development" inside the JSON.stringify function, like this: JSON.stringify函数中的“开发”,如下所示:
'NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
4) You have single and double quotes around '"development"' which would create the string with the double quotes which would be a different string to just the word development. 4)您在'“ development”'周围有单引号和双引号,这将创建带有双引号的字符串,该字符串与只是单词development的字符串不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.