From 325846d93808f7e05a6ed6c85b608ca9f25ab6ca Mon Sep 17 00:00:00 2001 From: HuiNeng6 <3650306360@qq.com> Date: Fri, 27 Mar 2026 12:43:23 +0800 Subject: [PATCH] feat: Add API health check route - Create GET /api/health endpoint - Returns status, uptime, and timestamp - Lightweight heartbeat for monitoring and setup verification Fixes: #4 --- backend/src/index.ts | 2 ++ backend/src/routes/health.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 backend/src/routes/health.ts diff --git a/backend/src/index.ts b/backend/src/index.ts index af578ea..af5ae65 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -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(); @@ -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}`); diff --git a/backend/src/routes/health.ts b/backend/src/routes/health.ts new file mode 100644 index 0000000..fcffdc9 --- /dev/null +++ b/backend/src/routes/health.ts @@ -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(), + }); +}); + +export default router; \ No newline at end of file