Files
YelayMaths/yelaymaths_api/src/health.controller.ts
T
2026-09-30 03:38:10 +08:00

24 lines
681 B
TypeScript

import { Controller, Get } from '@nestjs/common';
import { Public } from './common/auth';
import { PrismaService } from './prisma/prisma.service';
@Controller()
export class HealthController {
constructor(private readonly prisma: PrismaService) {}
/** 探活。数据库不可用时不返回 500,只标记 db 状态,便于区分进程挂掉与数据库挂掉。 */
@Public()
@Get('healthz')
async health() {
let db = 'ok';
try {
// 固定查生产库:探活关心的是主库是否可用
await this.prisma.main.$queryRaw`SELECT 1`;
} catch {
db = 'down';
}
return { status: 'ok', db, time: new Date().toISOString() };
}
}