feat: Add API health check route#6
Conversation
- Create GET /api/health endpoint - Returns status, uptime, and timestamp - Lightweight heartbeat for monitoring and setup verification Fixes: Sappymukherjee214#4
Review Summary by QodoAdd API health check endpoint for monitoring
WalkthroughsDescription• Adds GET /api/health endpoint for server monitoring • Returns status, uptime in seconds, and ISO timestamp • Integrates health check route into main Express application Diagramflowchart LR
A["index.ts"] -- "imports" --> B["health.ts"]
B -- "defines GET /api/health" --> C["Health Check Endpoint"]
C -- "returns" --> D["status, uptime, timestamp"]
A -- "registers route" --> E["app.use /api/health"]
File Changes1. backend/src/index.ts
|
Code Review by Qodo
1. Health always reports UP
|
| router.get('/', (req: Request, res: Response) => { | ||
| const now = new Date(); | ||
| const uptimeSeconds = Math.floor((Date.now() - startTime) / 1000); | ||
|
|
||
| res.status(200).json({ | ||
| status: 'UP', | ||
| uptime: uptimeSeconds, | ||
| timestamp: now.toISOString(), | ||
| }); | ||
| }); |
There was a problem hiding this comment.
1. Health always reports up 🐞 Bug ⛯ Reliability
GET /api/health always returns HTTP 200 with status "UP" without checking critical dependencies (notably the Prisma/DB connection), so monitoring/load-balancers can treat the instance as healthy while core API operations fail due to database outages.
Agent Prompt
## Issue description
`GET /api/health` currently returns `200` and `{ status: 'UP' }` regardless of whether core dependencies (notably the database via Prisma) are actually usable. This can cause false-positive health signals during DB outages.
## Issue Context
The backend instantiates a `PrismaClient` and controllers (e.g., auth) depend on it for request handling. A meaningful health check should reflect whether the service can perform its primary responsibilities.
## Fix Focus Areas
- backend/src/routes/health.ts[13-22]
- backend/src/index.ts[15-17]
## Suggested fix
- Make the handler `async` and perform a lightweight Prisma check (e.g., `await prisma.$queryRaw\`SELECT 1\`` or `await prisma.$executeRaw\`SELECT 1\``).
- On failure, return `503` with `status: 'DOWN'` (and optionally include per-dependency check statuses).
- Ensure the Prisma client used is the same long-lived instance (avoid creating a new PrismaClient per request).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Review Summary by QodoAdd API health check endpoint for monitoring
WalkthroughsDescription• Adds GET /api/health endpoint for server monitoring • Returns status, uptime in seconds, and ISO timestamp • Integrates health check route into main Express app Diagramflowchart LR
A["index.ts"] -- "imports" --> B["health.ts"]
B -- "defines GET /api/health" --> C["Health Check Endpoint"]
C -- "returns" --> D["status UP, uptime, timestamp"]
A -- "registers route" --> E["app.use /api/health"]
File Changes1. backend/src/index.ts
|
Code Review by Qodo
1. Health always reports UP
|
Implements GET /api/health endpoint for monitoring.
Returns status UP, uptime in seconds, and timestamp.
Fixes: #4