File tree Expand file tree Collapse file tree 4 files changed +47
-0
lines changed
Expand file tree Collapse file tree 4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import express from 'express';
22import dotenv from 'dotenv' ;
33import authRouter from './routes/auth' ;
44import fileRouter from './routes/file' ;
5+ import healthRouter from './routes/health' ;
56import cors from 'cors' ;
67
78dotenv . config ( ) ;
@@ -14,6 +15,8 @@ app.use("/api/auth", authRouter);
1415
1516app . use ( "/api/files" , fileRouter ) ;
1617
18+ app . use ( "/health" , healthRouter ) ;
19+
1720// Serve static files
1821app . use ( '/pdfjs' , express . static ( "public/pdfjs" ) ) ;
1922app . use ( '/build' , express . static ( "public/build" ) ) ;
Original file line number Diff line number Diff line change 1+ import { Request , Response } from "express" ;
2+ import prisma from "../../prismaClient/client" ;
3+
4+ export const detailedSeverHealthInfo = async ( req : Request , res : Response ) => {
5+
6+ const healthcheck = {
7+ message : "OK" ,
8+ uptime : process . uptime ( ) ,
9+ timeStamp : new Date ( ) . toISOString ( ) ,
10+ services : {
11+ database : "unknown"
12+ }
13+ }
14+
15+ try {
16+ // Prisma DB check
17+ await prisma . $queryRaw `SELECT 1` ;
18+ healthcheck . services . database = "connected" ;
19+
20+ res . status ( 200 ) . json ( healthcheck ) ;
21+ } catch ( error : any ) {
22+ healthcheck . services . database = "disconnected" ;
23+ healthcheck . message = error . message ;
24+ res . status ( 503 ) . json ( healthcheck ) ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ import { Request , Response } from "express" ;
2+
3+ export const simpleSeverHealthInfo = ( req : Request , res : Response ) => {
4+ res . status ( 200 ) . json ( {
5+ status : "OK" ,
6+ message : "👍 Sever is healthy"
7+ } )
8+ }
Original file line number Diff line number Diff line change 1+ import Express from "express"
2+ import { simpleSeverHealthInfo } from "../modules/health/simpleHealth" ;
3+ import { detailedSeverHealthInfo } from "../modules/health/detailedHealth" ;
4+
5+ const healthRouter = Express . Router ( ) ;
6+
7+ healthRouter . get ( "/" , simpleSeverHealthInfo ) ;
8+ healthRouter . get ( '/detailed' , detailedSeverHealthInfo ) ;
9+
10+ export default healthRouter ;
You can’t perform that action at this time.
0 commit comments