fix: docker health check

This commit is contained in:
Shrev Dev
2025-10-21 12:46:07 -05:00
parent bc0fcadda3
commit c23e6e9f12
2 changed files with 15 additions and 7 deletions
+1 -1
View File
@@ -23,7 +23,7 @@
destination = '/app/data' destination = '/app/data'
[http_service] [http_service]
internal_port = 8080 internal_port = 3000
auto_stop_machines = 'off' auto_stop_machines = 'off'
auto_start_machines = false auto_start_machines = false
min_machines_running = 1 min_machines_running = 1
+13 -5
View File
@@ -138,18 +138,26 @@ class UptimeKumaDiscordBot {
const port = parseInt(process.env.HEALTH_PORT || '3000', 10); const port = parseInt(process.env.HEALTH_PORT || '3000', 10);
this.healthServer = http.createServer((req, res) => { 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 isHealthy = this.discord.isConnected() && this.uptimeKuma.isConnected();
const status = isHealthy ? 'healthy' : 'unhealthy'; const status = isHealthy ? 'healthy' : 'unhealthy';
const statusCode = isHealthy ? 200 : 503; const statusCode = isHealthy ? 200 : 503;
res.writeHead(statusCode, { 'Content-Type': 'application/json' }); const body = JSON.stringify({
res.end(JSON.stringify({
status, status,
discord: this.discord.isConnected() ? 'connected' : 'disconnected', discord: this.discord.isConnected() ? 'connected' : 'disconnected',
uptimeKuma: this.uptimeKuma.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 { } else {
res.writeHead(404, { 'Content-Type': 'text/plain' }); res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not Found'); res.end('Not Found');