Different files per Heroku environment

时间:2018-03-23 00:34:38

标签: heroku heroku-toolbelt

I have two separate apps on Heroku that are very similar so they share the same master codebase. They are each set up as a different environment. They only differ in the values of a few environment variables. That's all working fine because environment variables can be set per environment.

But in addition the environment variables, there is one file that needs to be different between the two environments. This file needs to be named the same, but must have different contents.

How can I deploy one file in one environment and a different file in another?

2 个答案:

答案 0 :(得分:1)

如果不知道它是什么类型的文件以及你正在使用什么语言,这很难回答。

通用方法是将两个文件放在代码库中,例如sample_file_env_1.txtsample_file_env_2.txt,然后在Procfile或app启动脚本中调用另一个脚本来复制该文件取决于所设置的环境变量,到您期望的位置。

答案 1 :(得分:0)

虽然我更喜欢Navin的更一般的答案,但我碰巧使用Express并通过在get请求中提供正确的文件来解决问题:

app.get("/MyFile", (req, res) => {
    // Serve a different file based on the environment variable
    res.redirect(process.env.ACTUAL_FILE_PATH)
})