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'
|
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
|
||||||
|
|||||||
+14
-6
@@ -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');
|
||||||
|
|||||||
Reference in New Issue
Block a user