mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-25 22:21:26 +10:00
refactor(v4.0.0-alpha): beginning of a new era
This commit is contained in:
48
apps/server/src/health/health.controller.ts
Normal file
48
apps/server/src/health/health.controller.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { CacheInterceptor, CacheKey, CacheTTL } from "@nestjs/cache-manager";
|
||||
import { Controller, Get, NotFoundException, UseInterceptors } from "@nestjs/common";
|
||||
import { HealthCheck, HealthCheckService } from "@nestjs/terminus";
|
||||
import { RedisService } from "@songkeys/nestjs-redis";
|
||||
import { RedisHealthIndicator } from "@songkeys/nestjs-redis-health";
|
||||
|
||||
import { configSchema } from "../config/schema";
|
||||
import { BrowserHealthIndicator } from "./browser.health";
|
||||
import { DatabaseHealthIndicator } from "./database.health";
|
||||
import { StorageHealthIndicator } from "./storage.health";
|
||||
|
||||
@Controller("health")
|
||||
export class HealthController {
|
||||
constructor(
|
||||
private readonly health: HealthCheckService,
|
||||
private readonly database: DatabaseHealthIndicator,
|
||||
private readonly browser: BrowserHealthIndicator,
|
||||
private readonly storage: StorageHealthIndicator,
|
||||
private readonly redisService: RedisService,
|
||||
private readonly redis: RedisHealthIndicator,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@HealthCheck()
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
@CacheKey("health:check")
|
||||
@CacheTTL(30000) // 30 seconds
|
||||
check() {
|
||||
return this.health.check([
|
||||
() => this.database.isHealthy(),
|
||||
() => this.storage.isHealthy(),
|
||||
() => this.browser.isHealthy(),
|
||||
() => {
|
||||
return this.redis.checkHealth("redis", {
|
||||
type: "redis",
|
||||
timeout: 1000,
|
||||
client: this.redisService.getClient(),
|
||||
});
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
@Get("environment")
|
||||
environment() {
|
||||
if (process.env.NODE_ENV === "production") throw new NotFoundException();
|
||||
return configSchema.parse(process.env);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user