Allow JSON array and objects in env.var configs

This commit is contained in:
Cohee
2025-02-25 22:20:17 +02:00
parent 4edb069bd8
commit 0776f65193

View File

@@ -65,7 +65,9 @@ export function getConfigValue(key, defaultValue = null, typeConverter = null) {
function _getValue() {
const envKey = keyToEnv(key);
if (envKey in process.env) {
return process.env[envKey];
const needsJsonParse = defaultValue && typeof defaultValue === 'object';
const envValue = process.env[envKey];
return needsJsonParse ? (tryParse(envValue) ?? defaultValue) : envValue;
}
const config = getConfig();
return _.get(config, key, defaultValue);