All checks were successful
ci/woodpecker/push/api Pipeline was successful
Docker/load-balancer health probes hit GET /health every ~5s from 127.0.0.1, exhausting the rate limit and causing all subsequent checks to return 429 — making the service appear unhealthy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { Controller, Get } from "@nestjs/common";
|
|
import { SkipThrottle } from "@nestjs/throttler";
|
|
import { AppService } from "./app.service";
|
|
import { PrismaService } from "./prisma/prisma.service";
|
|
import type { ApiResponse, HealthStatus } from "@mosaic/shared";
|
|
import { successResponse } from "@mosaic/shared";
|
|
|
|
@Controller()
|
|
export class AppController {
|
|
constructor(
|
|
private readonly appService: AppService,
|
|
private readonly prisma: PrismaService
|
|
) {}
|
|
|
|
@Get()
|
|
getHello(): string {
|
|
return this.appService.getHello();
|
|
}
|
|
|
|
@Get("health")
|
|
@SkipThrottle()
|
|
async getHealth(): Promise<ApiResponse<HealthStatus>> {
|
|
const dbHealthy = await this.prisma.isHealthy();
|
|
const dbInfo = await this.prisma.getConnectionInfo();
|
|
|
|
const overallStatus = dbHealthy ? "healthy" : "degraded";
|
|
const packageVersion = process.env.npm_package_version;
|
|
|
|
return successResponse({
|
|
status: overallStatus,
|
|
timestamp: new Date().toISOString(),
|
|
...(packageVersion && { version: packageVersion }),
|
|
checks: {
|
|
database: {
|
|
status: dbHealthy ? "healthy" : "unhealthy",
|
|
message: dbInfo.connected
|
|
? `Connected to ${dbInfo.database ?? "unknown"} (${dbInfo.version ?? "unknown"})`
|
|
: "Database connection failed",
|
|
},
|
|
},
|
|
});
|
|
}
|
|
}
|