u
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user