#!/usr/bin/env node /** * CHORUS Services Website - Simplified Health Check Script * Validates that Next.js server is running correctly * Used by Docker HEALTHCHECK instruction */ const http = require('http'); const process = require('process'); const PORT = process.env.PORT || 80; const TIMEOUT = 5000; // 5 seconds /** * Make HTTP request to check service health * @returns {Promise} - True if healthy */ function checkHealth() { return new Promise((resolve) => { const options = { hostname: '127.0.0.1', // Force IPv4 instead of localhost port: PORT, path: '/', method: 'HEAD', timeout: TIMEOUT, headers: { 'User-Agent': 'HealthCheck/1.0' } }; const req = http.request(options, (res) => { const isHealthy = res.statusCode >= 200 && res.statusCode < 400; resolve(isHealthy); }); req.on('error', () => { resolve(false); }); req.on('timeout', () => { req.destroy(); resolve(false); }); req.setTimeout(TIMEOUT); req.end(); }); } /** * Main health check function */ async function main() { try { const healthy = await checkHealth(); process.exit(healthy ? 0 : 1); } catch (error) { process.exit(1); } } // Handle process signals process.on('SIGTERM', () => process.exit(1)); process.on('SIGINT', () => process.exit(1)); // Run health check main();