Genesis
This commit is contained in:
23
src/api/routes/health.js
Normal file
23
src/api/routes/health.js
Normal 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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user