diff --git a/ecosystem-test.config.cjs b/ecosystem-test.config.cjs index 3941ba0..312d004 100644 --- a/ecosystem-test.config.cjs +++ b/ecosystem-test.config.cjs @@ -7,10 +7,53 @@ // // These apps: // - Run from /var/www/flyer-crawler-test.projectium.com -// - Use NODE_ENV='test' (enables file logging in logger.server.ts) +// - Use NODE_ENV='staging' (enables file logging in logger.server.ts) // - Use Redis database 1 (isolated from production which uses database 0) // - Have distinct PM2 process names to avoid conflicts with production +// --- Load Environment Variables from .env file --- +// This allows PM2 to start without requiring the CI/CD pipeline to inject variables. +// The .env file should be created on the server with the required secrets. +// NOTE: We implement a simple .env parser since dotenv may not be installed. +const path = require('path'); +const fs = require('fs'); + +const envPath = path.join('/var/www/flyer-crawler-test.projectium.com', '.env'); +if (fs.existsSync(envPath)) { + console.log('[ecosystem-test.config.cjs] Loading environment from:', envPath); + const envContent = fs.readFileSync(envPath, 'utf8'); + const lines = envContent.split('\n'); + for (const line of lines) { + // Skip comments and empty lines + const trimmed = line.trim(); + if (!trimmed || trimmed.startsWith('#')) continue; + + // Parse KEY=value + const eqIndex = trimmed.indexOf('='); + if (eqIndex > 0) { + const key = trimmed.substring(0, eqIndex); + let value = trimmed.substring(eqIndex + 1); + // Remove quotes if present + if ( + (value.startsWith('"') && value.endsWith('"')) || + (value.startsWith("'") && value.endsWith("'")) + ) { + value = value.slice(1, -1); + } + // Only set if not already in environment (don't override CI/CD vars) + if (!process.env[key]) { + process.env[key] = value; + } + } + } + console.log('[ecosystem-test.config.cjs] Environment loaded successfully'); +} else { + console.warn('[ecosystem-test.config.cjs] No .env file found at:', envPath); + console.warn( + '[ecosystem-test.config.cjs] Environment variables must be provided by the shell or CI/CD.' + ); +} + // --- Environment Variable Validation --- // NOTE: We only WARN about missing secrets, not exit. // Calling process.exit(1) prevents PM2 from reading the apps array.