diff --git a/src/server/readConfig/readConfig.test.ts b/src/server/readConfig/readConfig.test.ts index 441eac7..5cf8c53 100644 --- a/src/server/readConfig/readConfig.test.ts +++ b/src/server/readConfig/readConfig.test.ts @@ -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', }, }) }) diff --git a/src/server/readConfig/readConfig.ts b/src/server/readConfig/readConfig.ts index f3b7783..e4b44ea 100644 --- a/src/server/readConfig/readConfig.ts +++ b/src/server/readConfig/readConfig.ts @@ -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) }