File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ import { NextResponse } from "next/server"
2+ import { sql } from "@/lib/db"
3+
4+ export async function GET ( ) {
5+ const appVersion = process . env . NEXT_PUBLIC_APP_VERSION || "unknown"
6+
7+ // Check database connection
8+ let databaseStatus = "DOWN"
9+ let databaseError : string | null = null
10+
11+ try {
12+ // Simple query to test the database connection
13+ await sql `SELECT 1 as test`
14+ databaseStatus = "UP"
15+ } catch ( error ) {
16+ console . error ( "Health check - Database connection failed:" , error )
17+ databaseError = error instanceof Error ? error . message : String ( error )
18+ }
19+
20+ const response = {
21+ status : "UP" ,
22+ database : databaseStatus ,
23+ version : appVersion ,
24+ }
25+
26+ // If database is down, include error details and return 503
27+ if ( databaseStatus === "DOWN" ) {
28+ return NextResponse . json (
29+ {
30+ ...response ,
31+ databaseError,
32+ } ,
33+ { status : 503 }
34+ )
35+ }
36+
37+ return NextResponse . json ( response )
38+ }
You can’t perform that action at this time.
0 commit comments