Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import extractRoutes from './routes/extract.js';
import exportRoutes from './routes/export.js';
import authRoutes from './routes/auth.js';
import paymentRoutes from './routes/payment.js';
import healthRoutes from './routes/health.js';

dotenv.config();

Expand All @@ -32,6 +33,7 @@ app.use('/api/extract', extractRoutes);
app.use('/api/export', exportRoutes);
app.use('/api/auth', authRoutes);
app.use('/api/payment', paymentRoutes);
app.use('/api/health', healthRoutes);

app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
Expand Down
24 changes: 24 additions & 0 deletions backend/src/routes/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Router, Request, Response } from 'express';

const router = Router();

// Store server start time
const startTime = Date.now();

/**
* GET /api/health
* Health check endpoint for monitoring and setup verification
* Returns server status, uptime, and timestamp
*/
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(),
});
});
Comment on lines +13 to +22
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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


export default router;