feat(06-02): create health check endpoint
- Returns 200 'ok' when database is accessible - Returns 503 'unhealthy' when database query fails - Simple text response for Docker HEALTHCHECK
This commit is contained in:
22
src/routes/health/+server.ts
Normal file
22
src/routes/health/+server.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { entries } from '$lib/server/db/schema';
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async () => {
|
||||||
|
try {
|
||||||
|
// Verify database connectivity with a simple query
|
||||||
|
db.select().from(entries).limit(1).all();
|
||||||
|
|
||||||
|
return new Response('ok', {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'text/plain' }
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Health check failed:', error);
|
||||||
|
|
||||||
|
return new Response('unhealthy', {
|
||||||
|
status: 503,
|
||||||
|
headers: { 'Content-Type': 'text/plain' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user