Do not always require JSON parsing from env vars
This commit is contained in:
parent
714b8f55db
commit
1ef92f6b19
@ -198,11 +198,13 @@ describe('readConfig', () => {
|
||||
const config = readConfig({
|
||||
PEERCALLS__TEST_VALUE__SUB_VALUE_1: '1',
|
||||
PEERCALLS__TEST_VALUE__SUB_VALUE_2: JSON.stringify({a: 2}),
|
||||
PEERCALLS__TEST_VALUE__SUB_VALUE_3: 'string',
|
||||
}, '/tmp', '/tmp')
|
||||
expect(config.value()).toEqual({
|
||||
testValue: {
|
||||
subValue1: 1,
|
||||
subValue2: {a: 2},
|
||||
subValue3: 'string',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@ -4,7 +4,7 @@ import { resolve, join } from 'path'
|
||||
import { safeLoad } from 'js-yaml'
|
||||
import _debug from 'debug'
|
||||
|
||||
const debug = _debug('peercalls')
|
||||
const debug = _debug('peercalls:config')
|
||||
|
||||
const isObject = (value: unknown) => value !== null && typeof value === 'object'
|
||||
|
||||
@ -175,8 +175,15 @@ export function readConfig(
|
||||
.forEach(shortKey => {
|
||||
cfg = cfg[shortKey] = cfg[shortKey] || {}
|
||||
})
|
||||
cfg[lastKey] = JSON.parse(value)
|
||||
|
||||
try {
|
||||
cfg[lastKey] = JSON.parse(value)
|
||||
} catch (err) {
|
||||
cfg[lastKey] = value
|
||||
}
|
||||
})
|
||||
|
||||
return new ReadConfig(mergeConfig(envConfig, config))
|
||||
const configWithEnv = mergeConfig(envConfig, config)
|
||||
debug('Read configuration: %j', configWithEnv)
|
||||
return new ReadConfig(configWithEnv)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user