2 * @file Database Health Check API Endpoint
4 * Provides simple health check endpoint to verify database connectivity and API availability.
5 * Returns current database timestamp to confirm both database connection and query execution
6 * are functioning correctly. Useful for monitoring systems, load balancers, and uptime checks.
9 * - **No authentication**: Public endpoint for health monitoring
10 * - **Database connectivity test**: Executes simple SELECT NOW() query
11 * - **Fast response**: Minimal processing for sub-100ms response time
14 * - Load balancer health checks (ALB, ELB, HAProxy)
15 * - Kubernetes liveness/readiness probes
16 * - Monitoring systems (Prometheus, Datadog, New Relic)
17 * - CI/CD pipeline validation
18 * - Manual diagnostic checks
21 * @requires ../services/db - PostgreSQL database pool
24const express = require('express');
25const router = express.Router();
26const pool = require('../services/db');
29 * @api {get} /test Database Health Check
30 * @apiName DatabaseHealthCheck
33 * Verifies database connectivity by executing simple SELECT NOW() query and returning
34 * current database timestamp. Used by monitoring systems and load balancers to determine
35 * if API and database are healthy.
36 * @apiPermission public
37 * @apiNote No authentication required - designed for health check systems
38 * @apiSuccess {string} time Current database timestamp (ISO 8601 format)
39 * @apiError (500) {String} error "Database connection failed" (plaintext, not JSON)
40 * @apiExample {curl} Example Request:
41 * curl https://api.ibghub.com/api/test
42 * @apiExample {json} Example Response:
44 * "time": "2025-01-15T14:22:35.123Z"
48router.get('/', async (req, res) => {
50 const result = await pool.query('SELECT NOW()');
51 res.json({ time: result.rows[0].now });
53 console.error('DB connection error:', err);
54 res.status(500).send('Database connection failed');
58module.exports = router;