From 61b38d5b030e0ed15ef04fc627511a74d7fb6b7f Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 9 Nov 2025 19:21:17 +0100 Subject: [PATCH] Add `/ready` for api --- api/src/base.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/api/src/base.ts b/api/src/base.ts index 5f8d0dc6..cbd91681 100644 --- a/api/src/base.ts +++ b/api/src/base.ts @@ -14,6 +14,7 @@ import { showsH } from "./controllers/shows/shows"; import { staffH } from "./controllers/staff"; import { studiosH } from "./controllers/studios"; import { videosReadH, videosWriteH } from "./controllers/videos"; +import { db } from "./db"; import type { KError } from "./models/error"; export const base = new Elysia({ name: "base" }) @@ -58,6 +59,33 @@ export const base = new Elysia({ name: "base" }) detail: { description: "Check if the api is healthy." }, response: { 200: t.Object({ status: t.Literal("healthy") }) }, }) + .get( + "/ready", + async ({ status }) => { + try { + await db.execute("select 1"); + return { status: "healthy", database: "healthy" } as const; + } catch (e) { + return status(500, { + status: "unhealthy", + database: e, + }); + } + }, + { + detail: { description: "Check if the api is healthy." }, + response: { + 200: t.Object({ + status: t.Literal("healthy"), + database: t.Literal("healthy"), + }), + 500: t.Object({ + status: t.Literal("unhealthy"), + database: t.Any(), + }), + }, + }, + ) .as("global"); export const prefix = "/api";