diff --git a/fly.toml b/fly.toml index 27ad703..6ecfd2c 100644 --- a/fly.toml +++ b/fly.toml @@ -23,7 +23,7 @@ destination = '/app/data' [http_service] - internal_port = 8080 + internal_port = 3000 auto_stop_machines = 'off' auto_start_machines = false min_machines_running = 1 diff --git a/src/index.ts b/src/index.ts index 9962420..c46b520 100644 --- a/src/index.ts +++ b/src/index.ts @@ -138,18 +138,26 @@ class UptimeKumaDiscordBot { const port = parseInt(process.env.HEALTH_PORT || '3000', 10); this.healthServer = http.createServer((req, res) => { - if (req.url === '/health' && req.method === 'GET') { + if (req.url === '/health' && (req.method === 'GET' || req.method === 'HEAD')) { const isHealthy = this.discord.isConnected() && this.uptimeKuma.isConnected(); const status = isHealthy ? 'healthy' : 'unhealthy'; const statusCode = isHealthy ? 200 : 503; - - res.writeHead(statusCode, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify({ + + const body = JSON.stringify({ status, discord: this.discord.isConnected() ? 'connected' : 'disconnected', uptimeKuma: this.uptimeKuma.isConnected() ? 'connected' : 'disconnected', - timestamp: new Date().toISOString() - })); + timestamp: new Date().toISOString(), + }); + + res.writeHead(statusCode, { + 'Content-Type': 'application/json', + 'Content-Length': Buffer.byteLength(body), + }); + + // For HEAD, send headers only + if (req.method === 'HEAD') return res.end(); + return res.end(body); } else { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('Not Found');