first commit
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
const configLoader = require('./configLoader');
|
||||
const logger = require('./logger');
|
||||
|
||||
const validateConfiguration = () => {
|
||||
try {
|
||||
console.log('🔍 Validating Reason Flow Configuration...\n');
|
||||
|
||||
const config = configLoader.getAll();
|
||||
const env = configLoader.getEnvironment();
|
||||
|
||||
console.log(`Environment: ${env}`);
|
||||
console.log(`Server: ${config.server.host}:${config.server.port}`);
|
||||
console.log(`Database: ${config.database.host}:${config.database.port}/${config.database.name}`);
|
||||
console.log(`CORS Origin: ${config.server.corsOrigin}\n`);
|
||||
|
||||
// Check required configurations
|
||||
const checks = [
|
||||
{
|
||||
name: 'Groq API Key',
|
||||
value: config.apis.groq.apiKey,
|
||||
required: true,
|
||||
valid: config.apis.groq.apiKey && config.apis.groq.apiKey !== 'your_groq_api_key_here'
|
||||
},
|
||||
{
|
||||
name: 'JWT Secret',
|
||||
value: config.auth.jwtSecret,
|
||||
required: true,
|
||||
valid: config.auth.jwtSecret && config.auth.jwtSecret !== 'your_jwt_secret_here_make_it_long_and_secure'
|
||||
},
|
||||
{
|
||||
name: 'Database Password',
|
||||
value: config.database.password,
|
||||
required: true,
|
||||
valid: config.database.password && config.database.password !== 'your_password_here'
|
||||
},
|
||||
{
|
||||
name: 'OpenAI API Key',
|
||||
value: config.apis.openai.apiKey,
|
||||
required: false,
|
||||
valid: config.apis.openai.apiKey && config.apis.openai.apiKey !== 'your_openai_api_key_here'
|
||||
},
|
||||
{
|
||||
name: 'SERP API Key',
|
||||
value: config.apis.serp.apiKey,
|
||||
required: false,
|
||||
valid: config.apis.serp.apiKey && config.apis.serp.apiKey !== 'your_serp_api_key_here'
|
||||
}
|
||||
];
|
||||
|
||||
console.log('Configuration Checks:');
|
||||
console.log('====================');
|
||||
|
||||
let allValid = true;
|
||||
let hasWarnings = false;
|
||||
|
||||
checks.forEach(check => {
|
||||
const status = check.valid ? '✅' : (check.required ? '❌' : '⚠️');
|
||||
const required = check.required ? '(Required)' : '(Optional)';
|
||||
|
||||
console.log(`${status} ${check.name} ${required}`);
|
||||
|
||||
if (!check.valid && check.required) {
|
||||
allValid = false;
|
||||
} else if (!check.valid && !check.required) {
|
||||
hasWarnings = true;
|
||||
}
|
||||
});
|
||||
|
||||
console.log('\n');
|
||||
|
||||
// Environment-specific checks
|
||||
if (env === 'production') {
|
||||
console.log('Production Environment Checks:');
|
||||
console.log('==============================');
|
||||
|
||||
const prodChecks = [
|
||||
{
|
||||
name: 'JWT Secret Security',
|
||||
valid: config.auth.jwtSecret !== 'dev_secret_key_change_in_production',
|
||||
message: 'JWT secret should be changed for production'
|
||||
},
|
||||
{
|
||||
name: 'Database SSL',
|
||||
valid: config.database.ssl,
|
||||
message: 'Database SSL is recommended for production'
|
||||
},
|
||||
{
|
||||
name: 'Debug Mode',
|
||||
valid: !config.development.debugMode,
|
||||
message: 'Debug mode should be disabled in production'
|
||||
},
|
||||
{
|
||||
name: 'Verbose Logging',
|
||||
valid: !config.development.verboseLogging,
|
||||
message: 'Verbose logging should be disabled in production'
|
||||
}
|
||||
];
|
||||
|
||||
prodChecks.forEach(check => {
|
||||
const status = check.valid ? '✅' : '⚠️';
|
||||
console.log(`${status} ${check.name}: ${check.message}`);
|
||||
|
||||
if (!check.valid) {
|
||||
hasWarnings = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log('\n');
|
||||
|
||||
// Summary
|
||||
if (allValid) {
|
||||
console.log('🎉 Configuration validation passed!');
|
||||
|
||||
if (hasWarnings) {
|
||||
console.log('⚠️ Some optional configurations are missing or need attention.');
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
console.log('❌ Configuration validation failed!');
|
||||
console.log('Please fix the required configuration issues before starting the application.');
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Configuration validation error:', error.message);
|
||||
logger.error('Configuration validation error:', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const showConfiguration = () => {
|
||||
try {
|
||||
console.log('📋 Current Configuration:');
|
||||
console.log('========================\n');
|
||||
|
||||
const config = configLoader.getAll();
|
||||
|
||||
console.log('Server Configuration:');
|
||||
console.log(` Port: ${config.server.port}`);
|
||||
console.log(` Host: ${config.server.host}`);
|
||||
console.log(` Environment: ${config.server.env}`);
|
||||
console.log(` CORS Origin: ${config.server.corsOrigin}\n`);
|
||||
|
||||
console.log('Database Configuration:');
|
||||
console.log(` Host: ${config.database.host}`);
|
||||
console.log(` Port: ${config.database.port}`);
|
||||
console.log(` Name: ${config.database.name}`);
|
||||
console.log(` User: ${config.database.user}`);
|
||||
console.log(` SSL: ${config.database.ssl}\n`);
|
||||
|
||||
console.log('API Configuration:');
|
||||
console.log(` Groq Model: ${config.apis.groq.model}`);
|
||||
console.log(` Groq API Key: ${config.apis.groq.apiKey ? 'Set' : 'Not Set'}`);
|
||||
console.log(` OpenAI API Key: ${config.apis.openai.apiKey ? 'Set' : 'Not Set'}`);
|
||||
console.log(` SERP API Key: ${config.apis.serp.apiKey ? 'Set' : 'Not Set'}\n`);
|
||||
|
||||
console.log('Security Configuration:');
|
||||
console.log(` JWT Secret: ${config.auth.jwtSecret ? 'Set' : 'Not Set'}`);
|
||||
console.log(` JWT Expires In: ${config.auth.jwtExpiresIn}`);
|
||||
console.log(` Helmet Enabled: ${config.security.helmetEnabled}\n`);
|
||||
|
||||
console.log('Development Configuration:');
|
||||
console.log(` Debug Mode: ${config.development.debugMode}`);
|
||||
console.log(` Verbose Logging: ${config.development.verboseLogging}`);
|
||||
console.log(` Hot Reload: ${config.development.hotReload}\n`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error showing configuration:', error.message);
|
||||
}
|
||||
};
|
||||
|
||||
// Run validation if this file is executed directly
|
||||
if (require.main === module) {
|
||||
const args = process.argv.slice(2);
|
||||
const command = args[0] || 'validate';
|
||||
|
||||
switch (command) {
|
||||
case 'validate':
|
||||
const isValid = validateConfiguration();
|
||||
process.exit(isValid ? 0 : 1);
|
||||
break;
|
||||
case 'show':
|
||||
showConfiguration();
|
||||
break;
|
||||
default:
|
||||
console.log('Usage: node validateConfig.js [validate|show]');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateConfiguration,
|
||||
showConfiguration
|
||||
};
|
||||
Reference in New Issue
Block a user