How do I deploy to heroku from git when my API key is in a .gitignore file?

感情迁移 提交于 2019-12-08 03:30:25

问题


I have my API key set to a variable in an apikey.js file, and I reference the variable in another javascript file where the API key is supposed to be.

I added apikey.js to .gitignore so that people wouldn't see it when I pushed it to my (public) github account.

However, when I try to deploy, the app doesn't work because of the .gitignore.

How can I continue to push up files omitting the API key to my repo on git while deploying on heroku?


回答1:


use https://github.com/ddollar/heroku-config, and you can keep your secrets in a file called .env and ignore that in .gitignore

Install it with heroku plugins:install git://github.com/ddollar/heroku-config.git

You can run heroku config:pull --overwrite --interactive to generate an initial .env file that includes your service secrets, etc, and heroku config:push to save it, remotely.

I am assuming that you are using node, since your config file is javascript. To get the values in your .env file in node use process.env. For example to connect to your mongolab in mongoose:

mongoose.connect(process.env.MONGOLAB_URI);

There is more about all this here: https://devcenter.heroku.com/articles/config-vars#local-setup



来源:https://stackoverflow.com/questions/19580313/how-do-i-deploy-to-heroku-from-git-when-my-api-key-is-in-a-gitignore-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!