简体   繁体   English

heroku中的环境变量

[英]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.

相关问题 heroku 环境变量返回未定义 - heroku environment variables return undefined 在Heroku中设置默认环境变量 - Setting default environment variables in Heroku 在Heroku上使用Javascript访问环境变量? - Accessing environment variables in Javascript on Heroku? express-stormpath无法识别要在Heroku上初始化的环境变量 - express-stormpath not recognizing environment variables to initialize on Heroku 在 Heroku 上部署 Javascript 文件时使用环境变量 - Using environment Variables in Javascript file when deploying it on Heroku 将Firebase Firestore连接到Heroku上托管的node.js服务器时,环境变量返回未定义 - Environment variables returning undefined when connecting Firebase Firestore to a node.js server hosted on Heroku 我应该在Heroku上使用小型个人应用程序的用户名和密码使用环境变量还是module.exports? - Should I use environment variables or module.exports for username and password for a small personal app on Heroku? 关于为什么我无法在jsforce auth函数中使用heroku环境变量的任何线索? - Any clue as to why I am not able to use heroku environment variables in my jsforce auth function? 如何使用node-config包含Heroku环境变量? - How does one include Heroku environment variables using node-config? Heroku 环境中的唤醒锁 - Wake lock in Heroku Environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM