Browse Source

Add health check API endpoint (#12)

* added health api

* proxy
Bernt Christian Egeland 7 months ago
parent
commit
57b970b74a
2 changed files with 12 additions and 1 deletions
  1. 11 0
      src/app/api/health/route.ts
  2. 1 1
      src/proxy.ts

+ 11 - 0
src/app/api/health/route.ts

@@ -0,0 +1,11 @@
+import { NextResponse } from "next/server";
+import { db } from "@/lib/db";
+
+export async function GET() {
+  try {
+    await db.$queryRaw`SELECT 1`;
+    return NextResponse.json({ status: "ok" });
+  } catch {
+    return NextResponse.json({ status: "error" }, { status: 503 });
+  }
+}

+ 1 - 1
src/proxy.ts

@@ -1,7 +1,7 @@
 import { NextRequest, NextResponse } from "next/server";
 import { getSessionCookie } from "better-auth/cookies";
 
-const publicPaths = ["/auth", "/api/auth", "/api/share", "/api/public", "/api/files/public", "/api/webhooks", "/share", "/terms"];
+const publicPaths = ["/auth", "/api/auth", "/api/health", "/api/share", "/api/public", "/api/files/public", "/api/webhooks", "/share", "/terms"];
 
 export async function proxy(request: NextRequest) {
   const { pathname } = request.nextUrl;