diff --git a/src-api/src/config/loader.ts b/src-api/src/config/loader.ts index 6b6a691..f41f0bd 100644 --- a/src-api/src/config/loader.ts +++ b/src-api/src/config/loader.ts @@ -157,6 +157,7 @@ class ConfigLoader { this.mergeConfig(fileConfig, 'file'); this.configPath = absolutePath; + this.loadEnvFromConfig(fileConfig as unknown as Record); console.log(`[ConfigLoader] Loaded config from: ${absolutePath}`); } catch (error) { @@ -164,6 +165,24 @@ class ConfigLoader { } } + /** + * Load custom env vars from config.json's "env" field. + * Values like "${VAR}" are resolved from process.env. + */ + private loadEnvFromConfig(fileConfig: Record): void { + const envMap = fileConfig.env as Record | 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 */