import { Inject, Controller, Get } from "@nestjs/common"; import { HealthService } from "./health.service.js"; import { ApiError } from "../../common/errors.js"; @Controller("health") export class HealthController { constructor(@Inject(HealthService) private readonly health: HealthService) {} @Get() liveness() { return this.health.liveness(); } /** * Readiness probe: 503 SERVICE_UNAVAILABLE when a dependency is down. * Canonical path `GET /api/v1/health/ready` (TASK-0009 + the K8s probe in * infrastructure/kubernetes/api.yaml). `GET /api/v1/health/deep` is kept as * a deprecated alias so existing references keep resolving. */ @Get("ready") async ready() { const result = await this.health.deep(); if (!result.ok) { const down = (["postgres", "redis"] as const).filter((k) => !result.checks[k]); throw new ApiError("SERVICE_UNAVAILABLE", 503, "Dependency unavailable.", [ { service: down.join(",") } ]); } return { status: "ready" as const, checks: result.checks }; } /** @deprecated alias of {@link ready} (pre-existing path). */ @Get("deep") async deep() { return this.ready(); } }