feat(api): add health check endpoints with @nestjs/terminus
Add HealthModule with /health (liveness) and /ready (readiness) probes. Readiness checks DB (Prisma) and Redis connectivity. Replaces the basic /health endpoint in AppController. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
20
apps/api/src/modules/health/infrastructure/prisma.health.ts
Normal file
20
apps/api/src/modules/health/infrastructure/prisma.health.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { HealthCheckError, HealthIndicator, type HealthIndicatorResult } from '@nestjs/terminus';
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
import { PrismaService } from '@modules/shared/infrastructure/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaHealthIndicator extends HealthIndicator {
|
||||
constructor(private readonly prisma: PrismaService) {
|
||||
super();
|
||||
}
|
||||
|
||||
async isHealthy(key: string): Promise<HealthIndicatorResult> {
|
||||
try {
|
||||
await this.prisma.$queryRawUnsafe('SELECT 1');
|
||||
return this.getStatus(key, true);
|
||||
} catch {
|
||||
throw new HealthCheckError('Database check failed', this.getStatus(key, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user