有没有办法从 Heroku 获取生产环境变量?
Is there a way to obtain production environment variables from Heroku?
我正在尝试通过 heroku local
命令在本地 运行 heroku。但是,这不使用 heroku config
.
中的环境变量
当我 运行 heroku local
我希望我的本地服务器使用在 heroku config
.
中找到的相同环境变量
我希望我的本地服务器能够模拟真实世界的服务器;这就是我尝试这样做的原因。
环境变量的全部意义在于它们是特定于环境的。在许多情况下,在开发中使用与生产中相同的数据库没有多大意义(例如,您的开发数据库可能与生产数据库不同,并且您可能真的不想在开发中发送电子邮件)。
无论如何,heroku local
支持从 .env
文件加载环境变量。你可以 create a local .env
file from your production environment variables:
Sometimes you may want to use the same config var in both local and Heroku environments. For each config var that you want to add to your .env
file, use the following command:
heroku config:get CONFIG-VAR-NAME -s >> .env
Do not commit the .env
file to source control. It should only be used for local configuration. Update your .gitignore
file to exclude the .env
file.
Keep in mind that your deployed production app may be connecting to different services than your local development app. For example, your deployed production app might have a DATABASE_URL
config var that references a Heroku Postgres database, but your local app might have a DATABASE_URL
variable in the .env
file that references your local installation of Postgres.
我正在尝试通过 heroku local
命令在本地 运行 heroku。但是,这不使用 heroku config
.
当我 运行 heroku local
我希望我的本地服务器使用在 heroku config
.
我希望我的本地服务器能够模拟真实世界的服务器;这就是我尝试这样做的原因。
环境变量的全部意义在于它们是特定于环境的。在许多情况下,在开发中使用与生产中相同的数据库没有多大意义(例如,您的开发数据库可能与生产数据库不同,并且您可能真的不想在开发中发送电子邮件)。
无论如何,heroku local
支持从 .env
文件加载环境变量。你可以 create a local .env
file from your production environment variables:
Sometimes you may want to use the same config var in both local and Heroku environments. For each config var that you want to add to your
.env
file, use the following command:heroku config:get CONFIG-VAR-NAME -s >> .env
Do not commit the
.env
file to source control. It should only be used for local configuration. Update your.gitignore
file to exclude the.env
file.Keep in mind that your deployed production app may be connecting to different services than your local development app. For example, your deployed production app might have a
DATABASE_URL
config var that references a Heroku Postgres database, but your local app might have aDATABASE_URL
variable in the.env
file that references your local installation of Postgres.