import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
export interface Config {
eventhorizon: {
baseURL: string;
apiToken: string;
};
logLevel: 'debug' | 'info' | 'warn' | 'error';
nodeEnv: 'development' | 'production' | 'test';
rateLimit: number;
apiTimeout: number;
}
export const config: Config = {
eventhorizon: {
baseURL: process.env.EVENTHORIZON_BASE_URL || 'http://localhost:8000',
apiToken: process.env.EVENTHORIZON_API_TOKEN || ''
},
logLevel: (process.env.LOG_LEVEL as Config['logLevel']) || 'info',
nodeEnv: (process.env.NODE_ENV as Config['nodeEnv']) || 'development',
rateLimit: parseInt(process.env.RATE_LIMIT || '100', 10),
apiTimeout: parseInt(process.env.API_TIMEOUT || '30000', 10)
};
// Validate config - returns error messages instead of throwing
export function validateConfig(): string[] {
const errors: string[] = [];
if (!config.eventhorizon.baseURL) {
errors.push('EVENTHORIZON_BASE_URL environment variable is required');
}
if (!config.eventhorizon.apiToken) {
errors.push('EVENTHORIZON_API_TOKEN environment variable is required');
}
if (config.nodeEnv === 'production' && config.eventhorizon.baseURL && !config.eventhorizon.baseURL.startsWith('https://')) {
errors.push('WARNING: Using HTTP in production is not recommended');
}
return errors;
}