refactor(v4.0.0-alpha): beginning of a new era

This commit is contained in:
Amruth Pillai
2023-11-05 12:31:42 +01:00
parent 0ba6a444e2
commit 22933bd412
505 changed files with 81829 additions and 0 deletions

View 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);
}
}