Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src-api/src/config/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,32 @@ class ConfigLoader {

this.mergeConfig(fileConfig, 'file');
this.configPath = absolutePath;
this.loadEnvFromConfig(fileConfig as unknown as Record<string, unknown>);

console.log(`[ConfigLoader] Loaded config from: ${absolutePath}`);
} catch (error) {
console.error(`[ConfigLoader] Error loading config file:`, error);
}
}

/**
* Load custom env vars from config.json's "env" field.
* Values like "${VAR}" are resolved from process.env.
*/
private loadEnvFromConfig(fileConfig: Record<string, unknown>): void {
const envMap = fileConfig.env as Record<string, string> | undefined;
if (!envMap || typeof envMap !== 'object') return;

for (const [key, value] of Object.entries(envMap)) {
if (typeof value !== 'string') continue;
const resolved = value.replace(/\$\{(\w+)\}/g, (_, name) => process.env[name] || '');
if (resolved && !process.env[key]) {
process.env[key] = resolved;
console.log(`[ConfigLoader] Injected env: ${key}`);
}
}
}

/**
* Load configuration from environment variables
*/
Expand Down