feat: add health check

This commit is contained in:
Elias Schneider
2024-11-24 18:53:32 +01:00
parent 9370292fe5
commit 058084ed64
3 changed files with 29 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ FROM node:20-alpine
# Delete default node user # Delete default node user
RUN deluser --remove-home node RUN deluser --remove-home node
RUN apk add --no-cache caddy su-exec RUN apk add --no-cache caddy curl su-exec
COPY ./reverse-proxy /etc/caddy/ COPY ./reverse-proxy /etc/caddy/
WORKDIR /app WORKDIR /app

View File

@@ -6,4 +6,11 @@ services:
ports: ports:
- 3000:80 - 3000:80
volumes: volumes:
- "./data:/app/backend/data" - "./data:/app/backend/data"
# Optional healthcheck
healthcheck:
test: "curl -f http://localhost/health"
interval: 1m30s
timeout: 5s
retries: 2
start_period: 10s

View File

@@ -0,0 +1,20 @@
import AppConfigService from '$lib/services/app-config-service';
import type { RequestHandler } from '@sveltejs/kit';
export const GET: RequestHandler = async () => {
const appConfigService = new AppConfigService();
let backendOk = true;
await appConfigService.list().catch(() => (backendOk = false));
return new Response(
JSON.stringify({
status: backendOk ? 'HEALTHY' : 'UNHEALTHY'
}),
{
status: backendOk ? 200 : 500,
headers: {
'content-type': 'application/json'
}
}
);
};