diff --git a/Dockerfile b/Dockerfile index 1c162ff..8232a09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ FROM node:20-alpine # Delete default node user 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/ WORKDIR /app diff --git a/docker-compose.yml b/docker-compose.yml index 9d1b3a6..96d0cb4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,4 +6,11 @@ services: ports: - 3000:80 volumes: - - "./data:/app/backend/data" \ No newline at end of file + - "./data:/app/backend/data" + # Optional healthcheck + healthcheck: + test: "curl -f http://localhost/health" + interval: 1m30s + timeout: 5s + retries: 2 + start_period: 10s \ No newline at end of file diff --git a/frontend/src/routes/health/+server.ts b/frontend/src/routes/health/+server.ts new file mode 100644 index 0000000..88bd74e --- /dev/null +++ b/frontend/src/routes/health/+server.ts @@ -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' + } + } + ); +};