gpt4 book ai didi

heroku - 在Heroku评论应用中将主机名设置为环境变量

转载 作者:行者123 更新时间:2023-12-03 12:51:18 25 4
gpt4 key购买 nike

我正在使用Heroku上与Github集成的Review Apps功能。在我的一个应用程序中,我设置了一个名为HOST_NAME的环境变量。例如,如果站点为http://www.purplebinder.com,则HOST_NAME将设置为www.purplebinder.com。它在我们使用Cookie和交易电子邮件的两个地方都使用过。

当我打开一个新的请求请求并启动一个评论应用程序时,HOST_NAME应该类似于purplebinder-pr-27.herokuapp.com

有没有办法自动设置该值? Heroku documentation on review apps表示一个env var可以从父应用程序继承一个值,也可以用app.json硬编码。这些方法在这里都不起作用,因为每次值都需要不同,并且与父应用程序也要不同。

Heroku还说可以通过“生成器”设置环境变量,但是没有详细说明。

这个问题可能是Setting ROOT_URL for Review Apps的重复,但是没有人回答。它也类似于How to get Heroku app name from inside the app,但是那里的答案涉及在创建应用程序之后运行脚本-在这里,我想将此值设置为初始构建的一部分。

最佳答案

https://devcenter.heroku.com/articles/github-integration-review-apps#heroku_app_name-and-heroku_parent_app_name:

To help with scripting, two special config vars are available to review apps. If you specify HEROKU_APP_NAME or HEROKU_PARENT_APP_NAME as required or optional config vars in your app.json file, Heroku will set those config vars to the new application name and the parent application name respectively. They will then be available for use in the postdeploy script so that you can do more advanced bootstrapping and configuration.

Here is an example app.json file that uses HEROKU_APP_NAME and HEROKU_PARENT_APP_NAME:

{
"name":"Advanced App",
"scripts": {
"postdeploy": "rake db:setup && bin/bootstrap"
},
"env": {
"HEROKU_APP_NAME": {
"required": true
},
"HEROKU_PARENT_APP_NAME": {
"required": true
}
}
}

关于heroku - 在Heroku评论应用中将主机名设置为环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38087125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com