Skip to content

Commit

Permalink
feat(config): add option to specify default value to env var expansion (
Browse files Browse the repository at this point in the history
#5020)

* feat: Add option to specify default value to env var expansion

* fix: remove unused capturing group for env var replacement

Co-authored-by: Nicolas Giard <[email protected]>
  • Loading branch information
mskrip and NGPixel authored Feb 19, 2022
1 parent 2815f38 commit de6d4be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dev/build/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ ssl:
provider: letsencrypt
domain: $(LETSENCRYPT_DOMAIN)
subscriberEmail: $(LETSENCRYPT_EMAIL)
logLevel: info
logFormat: $(LOG_FORMAT)
logLevel: $(LOG_LEVEL:info)
logFormat: $(LOG_FORMAT:default)
ha: $(HA_ACTIVE)
8 changes: 6 additions & 2 deletions server/helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ module.exports = {
/**
* Parse configuration value for environment vars
*
* Replaces `$(ENV_VAR_NAME)` with value of `ENV_VAR_NAME` environment variable.
*
* Also supports defaults by if provided as `$(ENV_VAR_NAME:default)`
*
* @param {any} cfg Configuration value
* @returns Parse configuration value
*/
parseConfigValue (cfg) {
return _.replace(
cfg,
/\$\(([A-Z0-9_]+)\)/g,
(fm, m) => { return process.env[m] }
/\$\(([A-Z0-9_]+)(?::(.+))?\)/g,
(fm, m, d) => { return process.env[m] || d }
)
},

Expand Down

0 comments on commit de6d4be

Please sign in to comment.