Browse Source

feat(config): add option to specify default value to env var expansion (#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 <github@ngpixel.com>
pull/5044/head
Marián Skrip 2 years ago
committed by GitHub
parent
commit
de6d4beef9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions
  1. 4
      dev/build/config.yml
  2. 8
      server/helpers/config.js

4
dev/build/config.yml

@ -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
server/helpers/config.js

@ -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 }
)
},

Loading…
Cancel
Save