mirror of
https://github.com/BrenBroZAYT/uptime-kuma-discord-bot.git
synced 2026-06-13 16:40:03 +00:00
fix: docker health check
This commit is contained in:
@@ -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
|
||||
|
||||
+14
-6
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user