@@ -49,6 +49,34 @@ export const authMiddleware: RequestHandler = async (req, res, next) => {
4949
5050/** ─── 3) Register all routes ─────────────────────────────────────────────── */
5151export async function registerRoutes ( app : Express ) : Promise < Server > {
52+
53+ // ─── 3.0) Health Check Endpoint ──────────────────────────────────
54+ app . get ( "/api/health" , async ( req : Request , res : Response ) => {
55+ try {
56+ // Test database connection
57+ const client = await pool . connect ( ) ;
58+ const dbResult = await client . query ( "SELECT NOW() as current_time" ) ;
59+ client . release ( ) ;
60+
61+ res . json ( {
62+ status : "healthy" ,
63+ timestamp : new Date ( ) . toISOString ( ) ,
64+ database : "connected" ,
65+ dbTime : dbResult . rows [ 0 ] . current_time ,
66+ server : "running"
67+ } ) ;
68+ } catch ( error : any ) {
69+ console . error ( "Health check failed:" , error ) ;
70+ res . status ( 503 ) . json ( {
71+ status : "unhealthy" ,
72+ timestamp : new Date ( ) . toISOString ( ) ,
73+ database : "disconnected" ,
74+ error : error . message ,
75+ server : "running"
76+ } ) ;
77+ }
78+ } ) ;
79+
5280 // ─── 3.1) Firebase Auth endpoints ──────────────────────────────────
5381
5482 app . post ( "/api/auth/user" , async ( req : Request , res : Response ) => {
@@ -1019,10 +1047,10 @@ export async function registerRoutes(app: Express): Promise<Server> {
10191047 }
10201048 } ) ;
10211049
1022- // Catch-All 404 only for /api/* routes
1023- app . use ( "/api" , ( req , res ) => {
1024- res . status ( 404 ) . json ( { message : "Not found" } ) ;
1025- } ) ;
1050+ // Catch-All 404 only for /api/* routes
1051+ app . use ( "/api" , ( req , res ) => {
1052+ res . status ( 404 ) . json ( { message : "Not found" } ) ;
1053+ } ) ;
10261054
10271055 // ────────────────────────────────────────────────────────────────
10281056 // ─── Finally, create and return the HTTP server ───────────────────
0 commit comments