This commit is contained in:
seb
2026-06-23 11:04:07 +02:00
commit 667f498573
19 changed files with 4299 additions and 0 deletions

23
src/api/routes/health.js Normal file
View File

@@ -0,0 +1,23 @@
import { ensureConnection } from '../../db/client.js';
/**
* Registers a database connectivity health check route.
* @param {import('express').Application} app - Express app
* @param {string} [basePath=''] - Optional URL prefix for all routes in this module
*/
export function register(app, basePath = '') {
/**
* @route GET /health
* @description Verifies the database client can establish a connection.
* @returns {Object} 200 - `{ ok: true }` when the database is reachable
* @returns {Object} 503 - `{ ok: false, error }` when the check fails
*/
app.get(`${basePath}/health`, async (_request, response) => {
try {
await ensureConnection();
response.status(200).json({ ok: true });
} catch (error) {
response.status(503).json({ ok: false, error: error.message });
}
});
}