From 01cfc48696e371f4fcea656dedd62090e707b670 Mon Sep 17 00:00:00 2001 From: Qin Guan Date: Sun, 17 Sep 2023 07:31:01 +0800 Subject: [PATCH] feat: health check --- server/api/healthz.get.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/server/api/healthz.get.ts b/server/api/healthz.get.ts index dc6574d..b70511c 100644 --- a/server/api/healthz.get.ts +++ b/server/api/healthz.get.ts @@ -1,3 +1,14 @@ -export default defineEventHandler((event) => { - return 1 -}) +import { sql } from 'drizzle-orm' + +export default defineLazyEventHandler(() => eventHandler(async (event) => { + try { + await event.context.database.run(sql`SELECT 1;`) + return { ok: true, now: new Date() } + } + catch (err) { + throw createError({ + statusCode: 500, + statusMessage: 'Internal Server Error', + }) + } +}))