import { gcsService } from "@services/gcs.service.js";
import { vaultService } from "@services/vault.service";
/**
* Health Controller - Handles health check operations
* @category Controllers
*/
export class HealthController {
/**
* Health check endpoint
* GET /api/health
* @param {Request} req Express request
* @param {Response} res Express response
* @returns {Promise<void>}
*/
static async healthCheck(req, res) {
const checks = {
gcs: false,
vault: false,
};
try {
checks.gcs = await gcsService.healthCheck();
}
catch { }
try {
checks.vault = await vaultService.healthCheck();
}
catch { }
// Determine overall status
const allHealthy = Object.values(checks).every((check) => check === true);
const status = allHealthy ? "ok" : "degraded";
res.status(allHealthy ? 200 : 503).json({
status,
timestamp: new Date().toISOString(),
service: "k12-backend-core",
checks,
});
}
}
export default HealthController;
Source