Skip to content

Commit 00aaf3b

Browse files
committed
feat: Add health check endpoint for database connectivity verification
1 parent 7977f1c commit 00aaf3b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

server/src/routes.ts

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as authController from './controllers/authController';
33
import * as categoryController from './controllers/categoryController';
44
import * as settingsController from './controllers/settingsController';
55
import * as taskController from './controllers/taskController';
6+
import db from './db';
67
import { authenticateToken } from './middleware/authMiddleware';
78

89
const router = express.Router();
@@ -30,4 +31,15 @@ router.post("/check-email", authController.checkEmail);
3031
router.get('/settings', authenticateToken, settingsController.getSettings);
3132
router.put('/settings', authenticateToken, settingsController.updateSettings);
3233

34+
// Health Check
35+
router.get('/health', async (req, res) => {
36+
try {
37+
await db.raw('SELECT 1'); // Quick DB connectivity check
38+
res.send('ok');
39+
} catch (error) {
40+
console.error('Health check failed:', error);
41+
res.status(503).send('error');
42+
}
43+
});
44+
3345
export default router;

0 commit comments

Comments
 (0)