feat(docker): add production Dockerfile, docker-compose setup and healthcheck API
This commit is contained in:
37
src/pages/api/health.ts
Normal file
37
src/pages/api/health.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||
|
||||
export const GET: APIRoute = async () => {
|
||||
let volumeStatus = 'ok';
|
||||
|
||||
try {
|
||||
// Prüfe Schreib- und Lesezugriff auf /app/data/
|
||||
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||
const testFile = path.join(DATA_DIR, '.healthcheck');
|
||||
await fs.writeFile(testFile, 'ok', 'utf-8');
|
||||
await fs.unlink(testFile);
|
||||
} catch {
|
||||
volumeStatus = 'error_data_volume_unwritable';
|
||||
}
|
||||
|
||||
const isHealthy = volumeStatus === 'ok';
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
status: isHealthy ? 'healthy' : 'unhealthy',
|
||||
uptime: process.uptime(),
|
||||
timestamp: new Date().toISOString(),
|
||||
volume_status: volumeStatus,
|
||||
node_version: process.version,
|
||||
}),
|
||||
{
|
||||
status: isHealthy ? 200 : 503,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user