refactor
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Environment configuration and validation
|
||||
*/
|
||||
|
||||
const requiredEnvVars = [
|
||||
'JWT_SECRET',
|
||||
'DB_HOST',
|
||||
'DB_USER',
|
||||
'DB_PASSWORD',
|
||||
'DB_NAME',
|
||||
'TMDB_API_KEY'
|
||||
];
|
||||
|
||||
export function validateConfig() {
|
||||
const missing = [];
|
||||
|
||||
for (const varName of requiredEnvVars) {
|
||||
if (!process.env[varName]) {
|
||||
missing.push(varName);
|
||||
}
|
||||
}
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error('❌ Missing required environment variables:');
|
||||
missing.forEach(varName => {
|
||||
console.error(` - ${varName}`);
|
||||
});
|
||||
console.error('\nPlease set these in your .env file or environment.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Validate JWT_SECRET is strong enough
|
||||
if (process.env.JWT_SECRET.length < 32) {
|
||||
console.error('❌ JWT_SECRET must be at least 32 characters long for security.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('✅ Environment configuration validated');
|
||||
}
|
||||
|
||||
export const config = {
|
||||
jwt: {
|
||||
secret: process.env.JWT_SECRET,
|
||||
expiresIn: '7d'
|
||||
},
|
||||
db: {
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: parseInt(process.env.DB_PORT || '3306', 10)
|
||||
},
|
||||
tmdb: {
|
||||
apiKey: process.env.TMDB_API_KEY,
|
||||
baseUrl: 'https://api.themoviedb.org/3'
|
||||
},
|
||||
server: {
|
||||
port: parseInt(process.env.PORT || '3000', 10)
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user