Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow oveeridng nested runtime config with env #1831

Merged
merged 10 commits into from
Nov 30, 2023
2 changes: 1 addition & 1 deletion playground/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default defineNitroConfig({});
export default defineNitroConfig({});
15 changes: 13 additions & 2 deletions src/runtime/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,21 @@ function _applyEnv(obj: object, parentKey = "") {
const subKey = parentKey ? `${parentKey}_${key}` : key;
const envValue = _getEnv(subKey);
if (_isObject(obj[key])) {
// Same as before
if (_isObject(envValue)) {
obj[key] = { ...obj[key], ...(envValue as any) };
obj[key] = { ...obj[key], ...(envValue as object) };
_applyEnv(obj[key], subKey);
}
// If envValue is undefined
// Then proceed to nested properties
else if (envValue === undefined) {
_applyEnv(obj[key], subKey);
}
// If envValue is a primitive other than undefined
// Then set objValue and ignore the nested properties
else {
obj[key] = envValue ?? obj[key];
}
_applyEnv(obj[key], subKey);
} else {
obj[key] = envValue ?? obj[key];
}
Expand Down