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

@@ -19,6 +19,7 @@ import { createLogger } from '../util/logger.js';
import v1Router from '../v1/index.js';
import { startBackendMonitor, stopBackendMonitor, isDevMode } from '../backendmonitor/server.js';
import { startBackupService, stopBackupService } from '../services/backupService.js';
import { startHealthMonitorService, stopHealthMonitorService } from '../services/healthMonitorService.js';
const apiLog = createLogger('api');
@@ -252,6 +253,12 @@ export async function startApi() {
apiLog.error('Failed to start Backup Service:', err.message);
}
try {
startHealthMonitorService();
} catch (err) {
apiLog.error('Failed to start Health Monitor Service:', err.message);
}
return server;
})();
@@ -275,6 +282,7 @@ export async function stopApi() {
// Same for the pooled sandbox threads that run `javascript_execute` / applets.
await shutdownJavascriptSandboxWorkers();
await stopBackupService();
await stopHealthMonitorService();
const closers = [];
if (server) {
const s = server;

View File

@@ -47,7 +47,7 @@ function respondWithAuthPayload(res, req, status, body) {
}
export const authMiddleware = async (req, res, next) => {
if (req.path === '/' || req.path === '/api/auth/login' || req.path === '/api/auth/logout' || req.path === '/api/health' || req.path === '/api/openapi.json') {
if (req.path === '/' || req.path === '/api/auth/login' || req.path === '/api/auth/logout' || req.path === '/api/health' || req.path === '/health' || req.path === '/api/openapi.json') {
return next();
}

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
}