diff --git a/apps/nextjs/src/middlewares/auth.middleware.ts b/apps/nextjs/src/middlewares/auth.middleware.ts index 361fea1e9..bd5d0edfb 100644 --- a/apps/nextjs/src/middlewares/auth.middleware.ts +++ b/apps/nextjs/src/middlewares/auth.middleware.ts @@ -22,6 +22,7 @@ const publicRoutes = [ "/api/health", "/aila/health", "/api/trpc/main/health.check", + "/api/trpc/main/health.prismaCheck", "/api/trpc/chat/chat.health.check", /** * The inngest route is protected using a signing key diff --git a/packages/api/src/router/health.ts b/packages/api/src/router/health.ts index a7d4f910b..14e585118 100644 --- a/packages/api/src/router/health.ts +++ b/packages/api/src/router/health.ts @@ -1,7 +1,24 @@ +import { aiLogger } from "@oakai/logger"; +import { TRPCError } from "@trpc/server"; + import { router, publicProcedure } from "../trpc"; +const log = aiLogger("db"); + export const healthRouter = router({ check: publicProcedure.query(() => { return "OK"; }), + prismaCheck: publicProcedure.query(async ({ ctx }) => { + try { + await ctx.prisma.prompt.count(); + return { status: "ok", message: "Prisma is connected" }; + } catch (error) { + log.error("Prisma health check failed", error); + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "Prisma connection failed", + }); + } + }), });