Files
CLProject/src/routes/healthRoutes.js
T
2026-04-22 22:39:26 +02:00

54 lines
1.4 KiB
JavaScript

import { Router } from 'express';
import { query } from '../db/pool.js';
import { asyncHandler } from '../utils/asyncHandler.js';
const router = Router();
/**
* @openapi
* /api/v1/health:
* get:
* summary: Health check
* description: Returns API and database connection status. Checks MariaDB connectivity.
* tags:
* - Health
* responses:
* 200:
* description: API is healthy
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: ok
* service:
* type: string
* example: check-list-poc-api
* database:
* type: string
* example: connected
*/
router.get(
'/',
asyncHandler(async (_req, res) => {
console.log(`PUBLIC: GET /api/v1/health`);
/*
* The health endpoint checks the database on purpose instead of only proving
* that Express can answer HTTP. In this project, the server is not useful if
* MariaDB is unavailable, so health must include that dependency.
*/
await query('SELECT 1 AS ok');
res.json({
status: 'ok',
service: 'check-list-poc-api',
database: 'connected'
});
})
);
export default router;