This commit is contained in:
seb
2026-10-18 20:48:50 +02:00
parent c06a5e3413
commit a717a05e8d
10 changed files with 294 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import { ensureConnection } from '../../db/store.js';
import { getStore } from '../../db/store.js';
/**
* Registers a database connectivity health check route.
@@ -12,12 +12,12 @@ export function register(app, basePath = '') {
* get:
* tags: [Health]
* summary: Database health check
* description: Verifies the database client can establish a connection.
* description: Verifies database connectivity and transaction execution by updating a healthcheck sequence.
* security: []
* x-markdown: health.md
* responses:
* 200:
* description: Database reachable
* description: Database reachable and healthy
* content:
* application/json:
* schema:
@@ -41,14 +41,20 @@ export function register(app, basePath = '') {
*/
// #region GET /health
app.get(`${basePath}/health`, async (_request, response) => {
const healthHandler = async (_request, response) => {
try {
await ensureConnection();
const store = await getStore();
await store.healthcheck.check();
response.status(200).json({ ok: true });
} catch (error) {
response.status(503).json({ ok: false, error: error.message });
}
});
};
app.get(`${basePath}/health`, healthHandler);
if (basePath) {
app.get('/health', healthHandler);
}
// #endregion
}