✨ Improve code readability by reformatting and reindenting environment validation logic
This commit is contained in:
@@ -13,24 +13,31 @@ const REQUIRED_ENV_VARS = {
|
||||
NODE_ENV: {
|
||||
required: true,
|
||||
description: 'Environment mode (development, production)',
|
||||
validate: (val) => ['development', 'production', 'test'].includes(val)
|
||||
validate: val => ['development', 'production', 'test'].includes(val)
|
||||
},
|
||||
PORT: {
|
||||
required: true,
|
||||
description: 'Server port number',
|
||||
validate: (val) => !isNaN(parseInt(val)) && parseInt(val) > 0 && parseInt(val) < 65536
|
||||
validate: val =>
|
||||
!isNaN(parseInt(val)) && parseInt(val) > 0 && parseInt(val) < 65536
|
||||
},
|
||||
|
||||
// Optional but recommended for production
|
||||
SESSION_SECRET: {
|
||||
required: false,
|
||||
description: 'Secret key for session encryption',
|
||||
warn: (val) => !val || val.length < 32 ? 'SESSION_SECRET should be at least 32 characters for security' : null
|
||||
warn: val =>
|
||||
!val || val.length < 32
|
||||
? 'SESSION_SECRET should be at least 32 characters for security'
|
||||
: null
|
||||
},
|
||||
FRONTEND_URL: {
|
||||
required: false,
|
||||
description: 'Frontend URL for CORS (required in production)',
|
||||
warn: (val, env) => env.NODE_ENV === 'production' && !val ? 'FRONTEND_URL should be set in production for proper CORS' : null
|
||||
warn: (val, env) =>
|
||||
env.NODE_ENV === 'production' && !val
|
||||
? 'FRONTEND_URL should be set in production for proper CORS'
|
||||
: null
|
||||
},
|
||||
|
||||
// Challonge OAuth (optional)
|
||||
@@ -63,14 +70,18 @@ export function validateEnvironment() {
|
||||
|
||||
// Check if required variable is missing
|
||||
if (config.required && !value) {
|
||||
errors.push(`Missing required environment variable: ${key} - ${config.description}`);
|
||||
errors.push(
|
||||
`Missing required environment variable: ${key} - ${config.description}`
|
||||
);
|
||||
missing.push(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validate value if present
|
||||
if (value && config.validate && !config.validate(value)) {
|
||||
errors.push(`Invalid value for ${key}: "${value}" - ${config.description}`);
|
||||
errors.push(
|
||||
`Invalid value for ${key}: "${value}" - ${config.description}`
|
||||
);
|
||||
}
|
||||
|
||||
// Check for warnings
|
||||
@@ -149,14 +160,21 @@ export function getConfig() {
|
||||
clientId: process.env.CHALLONGE_CLIENT_ID,
|
||||
clientSecret: process.env.CHALLONGE_CLIENT_SECRET,
|
||||
redirectUri: process.env.CHALLONGE_REDIRECT_URI,
|
||||
configured: !!(process.env.CHALLONGE_CLIENT_ID && process.env.CHALLONGE_CLIENT_SECRET)
|
||||
configured: !!(
|
||||
process.env.CHALLONGE_CLIENT_ID && process.env.CHALLONGE_CLIENT_SECRET
|
||||
)
|
||||
},
|
||||
|
||||
// CORS
|
||||
cors: {
|
||||
origin: process.env.NODE_ENV === 'production'
|
||||
origin:
|
||||
process.env.NODE_ENV === 'production'
|
||||
? process.env.FRONTEND_URL
|
||||
: ['http://localhost:5173', 'http://localhost:5174', 'http://localhost:5175']
|
||||
: [
|
||||
'http://localhost:5173',
|
||||
'http://localhost:5174',
|
||||
'http://localhost:5175'
|
||||
]
|
||||
},
|
||||
|
||||
// Security
|
||||
|
||||
Reference in New Issue
Block a user