33 lines
907 B
TypeScript
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"],
|
|
})
|