wikipedia-game-solver/apps/api/app/controllers/health/get_health_controller.ts
Théo LUDWIG 20ab889cf8
All checks were successful
Chromatic / chromatic (push) Successful in 2m3s
CI / ci (push) Successful in 4m16s
CI / commitlint (push) Successful in 14s
chore: improve type safety Tuyau
2024-08-18 01:31:02 +01:00

33 lines
907 B
TypeScript

import { healthChecks } from "#start/health.ts"
import { middleware } from "#start/kernel.ts"
import type { HttpContext } from "@adonisjs/core/http"
import router from "@adonisjs/core/services/router"
import type { HealthCheckReport } from "@adonisjs/core/types/health"
export default class get_health_controller {
public async handle(context: HttpContext): Promise<
| {
__response: HealthCheckReport
__status: 200
}
| {
__response: HealthCheckReport
__status: 503
}
> {
const report = await healthChecks.run()
if (!report.isHealthy) {
return context.response.serviceUnavailable(report)
}
return context.response.ok(report)
}
}
router
.get("/health", [get_health_controller])
.use(middleware.appKeySecurity())
.openapi({
description: "Ensure that the application is in a healthy state.",
tags: ["health"],
})