Skip to content

pdziok/env-rewrite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Environment Variables Rewriter

Why

To break direct dependency between application and it's run environment

Example

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.

TL;DR

Heroku addon Elastic Cloud provides env FOUNDELASTICSEARCH_URL. Bonsai Elastic Search addon provides BONSAI_URL.

Changing one addon to another require application changes.

Usage

Based on example given above:

Run your app with additional Environment Variable REWRITE_ENV

export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL

Inside 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;

Multiple rewrites

Separate rewrite directives with a comma (,). Example:

export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL,ES_URL:FOUNDELASTICSEARCH_URL

Chaning

Values are rewritten one after another which enables rewrite chain.

export REWRITE_ENV=ELASTICSEARCH_URL:FOUNDELASTICSEARCH_URL,ES_URL:ELASTICSEARCH_URL

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published