This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
wikipedia-game-solver/apps/api/app/controllers/health/get_health_controller.ts

33 lines
907 B
TypeScript
Raw Normal View History

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