fix
This commit is contained in:
parent
bd8a5bfe9e
commit
eb66086b2a
5 changed files with 59 additions and 37 deletions
|
|
@ -27,7 +27,7 @@ export class ConfigManager<T = Record<string, unknown>> {
|
|||
const configPath = options.configPath || join(process.cwd(), 'config');
|
||||
this.loaders = [
|
||||
new FileLoader(configPath, this.environment),
|
||||
new EnvLoader('STOCKBOT_'), // Prefix for env vars
|
||||
new EnvLoader(''), // No prefix for env vars to match our .env file
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ export * from './utils/validation';
|
|||
// Import necessary types for singleton
|
||||
import { ConfigManager } from './config-manager';
|
||||
import { AppConfig, appConfigSchema } from './schemas';
|
||||
import { FileLoader } from './loaders/file.loader';
|
||||
import { EnvLoader } from './loaders/env.loader';
|
||||
|
||||
// Create singleton instance
|
||||
let configInstance: ConfigManager<AppConfig> | null = null;
|
||||
|
|
@ -39,6 +41,27 @@ export async function initializeConfig(
|
|||
return configInstance.initialize(appConfigSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize configuration for a service in a monorepo
|
||||
* Automatically loads configs from:
|
||||
* 1. Root config directory (../../config)
|
||||
* 2. Service-specific config directory (./config)
|
||||
* 3. Environment variables
|
||||
*/
|
||||
export async function initializeServiceConfig(): Promise<AppConfig> {
|
||||
if (!configInstance) {
|
||||
const environment = process.env.NODE_ENV || 'development';
|
||||
configInstance = new ConfigManager<AppConfig>({
|
||||
loaders: [
|
||||
new FileLoader('../../config', environment), // Root config
|
||||
new FileLoader('./config', environment), // Service config
|
||||
new EnvLoader(''), // Environment variables
|
||||
]
|
||||
});
|
||||
}
|
||||
return configInstance.initialize(appConfigSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configuration
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue