Heroku pipeline - staging env variable carried into production

筅森魡賤 提交于 2019-11-30 19:11:31

You cannot rebuild the slug, the main point of pipelines is to move the same slug between apps.

What you need to do is to fetch API_URL at runtime and not during build process. You can put all envs in one file, for example env.js

export const API_URL = process.env.API_URL;
export const OTHER_VAR = process.env.OTHER_VAR;

And then just import what you need in other files

import { API_URL, OTHER_VAR } from 'env.js';

There might be situations where you need env vars during build time for different environments further downstream the pipeline. A setup like this for example:

Test |--> Prd Europe
     |--> Prd USA

Say, for SEO reasons, you want to have a different title for USA by using the env vars and it should be immediately available in the template, not after some miliseconds. This is in a pipeline not possible since the slug is built at test where only a single tenant can be served, and async loading is too slow. Some crawler may pick the placeholder title instead for example.

A workaround for this, besides not using a pipeline altogether, could be to generate multiple templates per environment (at build time). In this case two templates europe.html and usa.html. Then serve them based on the env vars at runtime by a web server. So if REGION === 'USA', serve usa.html with the env vars baked in at the test env.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!