Listory/src/health-check/health-check.controller.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-05-03 04:32:14 +02:00
import { Controller, Get } from "@nestjs/common";
2021-05-25 18:12:42 +02:00
import { ConfigService } from "@nestjs/config";
2022-07-12 20:32:55 +02:00
import { ApiTags } from "@nestjs/swagger";
2020-05-03 04:32:14 +02:00
import {
HealthCheck,
2021-05-25 18:12:42 +02:00
HealthCheckResult,
2020-05-03 04:32:14 +02:00
HealthCheckService,
HttpHealthIndicator,
2020-05-03 04:32:14 +02:00
TypeOrmHealthIndicator,
} from "@nestjs/terminus";
import { configureScope, Scope } from "@sentry/node";
2020-05-03 04:32:14 +02:00
2022-07-12 20:32:55 +02:00
@ApiTags("health")
2020-05-03 04:32:14 +02:00
@Controller("api/v1/health")
export class HealthCheckController {
constructor(
private readonly health: HealthCheckService,
private readonly http: HttpHealthIndicator,
2020-05-03 04:32:14 +02:00
private readonly typeorm: TypeOrmHealthIndicator,
private readonly config: ConfigService
) {}
@Get()
@HealthCheck()
async check(): Promise<HealthCheckResult> {
const health = await this.health.check([
2020-05-03 04:32:14 +02:00
() =>
this.http.pingCheck(
2020-05-03 04:32:14 +02:00
"spotify-web",
this.config.get<string>("SPOTIFY_WEB_API_URL")
),
() => this.typeorm.pingCheck("db"),
]);
configureScope((scope: Scope) => {
scope.setContext("health", {
status: health.status,
info: health.info,
error: health.error,
});
});
return health;
2020-05-03 04:32:14 +02:00
}
}