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' }
		});
	}
};
