Skip to content

Commit 44d5b00

Browse files
Fixing .env parsing error.
1 parent f1cf3c5 commit 44d5b00

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/common/configs/config.helper.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,27 @@ export function loadConfig() {
6464
* Parses environment variable JSON strings into JS objects
6565
*/
6666
function parseNestedJson(config: any): ApplicationConfig {
67-
return Object.keys(config).reduce((accumulator, configKey) => {
67+
// Only parse values that are JSON objects or arrays. We avoid
68+
// coercing simple primitives like numbers or booleans that happen
69+
// to be valid JSON (e.g. "1.0") because env vars are expected to
70+
// remain strings unless explicitly JSON objects/arrays.
71+
const initial = { ...config };
72+
return Object.keys(initial).reduce((accumulator, configKey) => {
73+
const raw = initial[configKey];
74+
if (typeof raw !== 'string') return accumulator;
75+
6876
try {
69-
accumulator[configKey] = JSON.parse(config[configKey]);
77+
const parsed = JSON.parse(raw);
78+
// Only replace when parsing yields an object or array
79+
if (parsed !== null && (typeof parsed === 'object' || Array.isArray(parsed))) {
80+
accumulator[configKey] = parsed;
81+
}
7082
} catch {
71-
/* empty */
83+
// leave original string value
7284
}
7385

74-
return config;
75-
}, config);
86+
return accumulator;
87+
}, initial) as ApplicationConfig;
7688
}
7789

7890
/**

0 commit comments

Comments
 (0)