当我的API密钥位于.gitignore文件中时,如何从git部署到heroku? [英] How do I deploy to heroku from git when my API key is in a .gitignore file?
问题描述
我将我的API密钥设置为apikey.js文件中的变量,并且在另一个应该将API密钥存在的javascript文件中引用了该变量.
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.
我在.gitignore中添加了apikey.js,这样当我将其推送到我的(公共)github帐户时,人们不会看到它.
I added apikey.js to .gitignore so that people wouldn't see it when I pushed it to my (public) github account.
但是,当我尝试进行部署时,由于.gitignore,该应用无法正常工作.
However, when I try to deploy, the app doesn't work because of the .gitignore.
在heroku上部署时,如何继续将文件中的API密钥省略掉到git上的仓库中?
How can I continue to push up files omitting the API key to my repo on git while deploying on heroku?
推荐答案
使用 https://github.com/ddollar/heroku-配置,您可以将机密保存在名为.env的文件中,而在.gitignore
use https://github.com/ddollar/heroku-config, and you can keep your secrets in a file called .env and ignore that in .gitignore
通过heroku plugins:install git://github.com/ddollar/heroku-config.git
您可以运行heroku config:pull --overwrite --interactive
生成包含服务机密等的初始.env文件,并运行heroku config:push
进行远程保存.
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.
我假设您正在使用node,因为您的配置文件是javascript.要在节点的.env文件中获取值,请使用process.env
.例如,以猫鼬连接到您的mongolab:
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);
这里有更多相关信息: https://devcenter.heroku.com/articles/config -vars#local-setup
There is more about all this here: https://devcenter.heroku.com/articles/config-vars#local-setup
这篇关于当我的API密钥位于.gitignore文件中时,如何从git部署到heroku?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!