问题
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