To break direct dependency between application and it's run environment
Running application on heroku and using add-ons causes adding Heroku Config Vars. Those Vars become Environment Variables within running dyno.
Heroku Vars are usually prefixed with add-on alias causing app to use runtime configuration values.
Some of addons aliases cannot be changed.
Heroku addon Elastic Cloud provides env FOUNDELASTICSEARCH_URL.
Bonsai Elastic Search addon provides BONSAI_URL.
Changing one addon to another require application changes.
Based on example given above:
Run your app with additional Environment Variable REWRITE_ENV
export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URLInside your application rewrite envs before using any of them (preferably in the beginning of the entrypoint)
require('env-rewrite').rewrite()Now ELASTICSEARCH_URL env has value of FOUNDELASTICSEARCH_URL;
Separate rewrite directives with a comma (,). Example:
export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL,ES_URL:FOUNDELASTICSEARCH_URLValues are rewritten one after another which enables rewrite chain.
export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL,ES_URL:ELASTICSEARCH_URL