diff --git a/code/utils/deploy-pokedex.js b/code/utils/deploy-pokedex.js index c88a93d..e3fcbdf 100644 --- a/code/utils/deploy-pokedex.js +++ b/code/utils/deploy-pokedex.js @@ -1,23 +1,23 @@ /** * DEPRECATED: Use deploy.sh instead - * + * * This utility is being phased out in favor of the comprehensive deploy.sh script * located at code/websites/pokedex.online/deploy.sh - * + * * Migration guide: * Old: node code/utils/deploy-pokedex.js --target internal * New: cd code/websites/pokedex.online && ./deploy.sh --target production - * + * * Old: node code/utils/deploy-pokedex.js --target local * New: cd code/websites/pokedex.online && ./deploy.sh --target local - * + * * The new deploy.sh provides: * - Environment-specific builds using Vite modes * - Automatic build verification * - Pre-deployment validation * - Integrated testing * - Better error handling - * + * * This file will be removed in a future update. */ diff --git a/code/websites/pokedex.online/scripts/verify-build.js b/code/websites/pokedex.online/scripts/verify-build.js index 3666d36..860460b 100644 --- a/code/websites/pokedex.online/scripts/verify-build.js +++ b/code/websites/pokedex.online/scripts/verify-build.js @@ -1,9 +1,9 @@ /** * Build Verification Script - * + * * Extracts and validates environment variables embedded in the built bundle. * Ensures redirect URIs match the expected deployment target. - * + * * Usage: * BUILD_TARGET=docker-local npm run build:verify * BUILD_TARGET=production npm run build:verify @@ -36,18 +36,20 @@ function log(color, symbol, message) { function findBuiltAssets() { const distPath = path.resolve(__dirname, '../dist/assets'); - + if (!fs.existsSync(distPath)) { throw new Error('dist/assets directory not found. Run build first.'); } - + const files = fs.readdirSync(distPath); - const jsFiles = files.filter(f => f.endsWith('.js') && f.startsWith('index-')); - + const jsFiles = files.filter( + f => f.endsWith('.js') && f.startsWith('index-') + ); + if (jsFiles.length === 0) { throw new Error('No built JavaScript files found in dist/assets/'); } - + return jsFiles.map(f => path.join(distPath, f)); } @@ -59,58 +61,58 @@ function extractRedirectUri(content) { /redirectUri[\"']?\s*[:=]\s*[\"']([^\"']+oauth\/callback)[\"']/, /(https?:\/\/[^\"'\s]+\/oauth\/callback)/ ]; - + for (const pattern of patterns) { const match = content.match(pattern); if (match && match[1]) { return match[1]; } } - + return null; } function verifyBuild() { console.log('\n🔍 Build Verification\n'); - + // Get target from environment variable const target = process.env.BUILD_TARGET || 'local'; - + if (!EXPECTED_URIS[target]) { log('red', '❌', `Invalid BUILD_TARGET: ${target}`); log('blue', 'ℹ', 'Valid targets: docker-local, production'); process.exit(1); } - + const expectedUri = EXPECTED_URIS[target]; log('blue', 'ℹ', `Deployment target: ${target}`); log('blue', 'ℹ', `Expected redirect URI: ${expectedUri}`); - + try { // Find built assets const assetFiles = findBuiltAssets(); log('green', '✅', `Found ${assetFiles.length} built asset(s)`); - + // Search for redirect URI in all assets let foundUri = null; for (const assetFile of assetFiles) { const content = fs.readFileSync(assetFile, 'utf8'); const uri = extractRedirectUri(content); - + if (uri) { foundUri = uri; break; } } - + if (!foundUri) { log('yellow', '⚠', 'Could not find Discord redirect URI in bundle'); log('blue', 'ℹ', 'This may be OK if OAuth is not used'); process.exit(0); } - + log('blue', 'ℹ', `Found redirect URI: ${foundUri}`); - + // Validate URI matches expected if (foundUri === expectedUri) { log('green', '✅', 'Redirect URI matches expected value!'); @@ -121,13 +123,18 @@ function verifyBuild() { log('blue', 'ℹ', `Expected: ${expectedUri}`); log('blue', 'ℹ', `Found: ${foundUri}`); console.log('\n❌ Build verification failed\n'); - console.log('This usually means the wrong .env.{mode} file was used during build.'); - console.log('Check that you\'re using the correct Vite mode flag:\n'); - console.log(' vite build --mode docker-local (for local Docker deployment)'); - console.log(' vite build --mode production (for Synology deployment)\n'); + console.log( + 'This usually means the wrong .env.{mode} file was used during build.' + ); + console.log("Check that you're using the correct Vite mode flag:\n"); + console.log( + ' vite build --mode docker-local (for local Docker deployment)' + ); + console.log( + ' vite build --mode production (for Synology deployment)\n' + ); process.exit(1); } - } catch (error) { log('red', '❌', `Verification error: ${error.message}`); process.exit(1); diff --git a/code/websites/pokedex.online/server/utils/env-validator.js b/code/websites/pokedex.online/server/utils/env-validator.js index 6d41b5a..677fdc3 100644 --- a/code/websites/pokedex.online/server/utils/env-validator.js +++ b/code/websites/pokedex.online/server/utils/env-validator.js @@ -35,24 +35,30 @@ const REQUIRED_ENV_VARS = { description: 'Frontend URL for CORS', validate: (val, env) => { if (!val) return false; - + // Validate that FRONTEND_URL matches DEPLOYMENT_TARGET (if set) const target = env?.DEPLOYMENT_TARGET; if (!target) return true; // Skip validation if target not set yet - + if (target === 'dev' && !val.includes('localhost:5173')) { - console.error('⚠️ FRONTEND_URL should be http://localhost:5173 for dev target'); + console.error( + '⚠️ FRONTEND_URL should be http://localhost:5173 for dev target' + ); return false; } if (target === 'docker-local' && !val.includes('localhost:8099')) { - console.error('⚠️ FRONTEND_URL should be http://localhost:8099 for docker-local target'); + console.error( + '⚠️ FRONTEND_URL should be http://localhost:8099 for docker-local target' + ); return false; } if (target === 'production' && !val.includes('app.pokedex.online')) { - console.error('⚠️ FRONTEND_URL should be https://app.pokedex.online for production target'); + console.error( + '⚠️ FRONTEND_URL should be https://app.pokedex.online for production target' + ); return false; } - + return true; } }, @@ -137,7 +143,9 @@ export function validateOrExit(exitOnError = true) { // Print validation results console.log('\n🔍 Environment Validation:'); - console.log(` DEPLOYMENT_TARGET: ${process.env.DEPLOYMENT_TARGET || 'not set'}`); + console.log( + ` DEPLOYMENT_TARGET: ${process.env.DEPLOYMENT_TARGET || 'not set'}` + ); console.log(` NODE_ENV: ${process.env.NODE_ENV || 'not set'}`); console.log(` PORT: ${process.env.PORT || 'not set'}`); console.log(` FRONTEND_URL: ${process.env.FRONTEND_URL || 'not set'}`); @@ -180,7 +188,7 @@ export function validateOrExit(exitOnError = true) { export function getConfig() { const deploymentTarget = process.env.DEPLOYMENT_TARGET || 'dev'; const frontendUrl = process.env.FRONTEND_URL; - + return { deploymentTarget, nodeEnv: process.env.NODE_ENV || 'development',