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,
|
2022-06-11 14:02:48 +02:00
|
|
|
HttpHealthIndicator,
|
2020-05-03 04:32:14 +02:00
|
|
|
TypeOrmHealthIndicator,
|
|
|
|
|
} from "@nestjs/terminus";
|
2022-06-11 14:02:48 +02:00
|
|
|
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,
|
2021-06-22 20:43:06 +02:00
|
|
|
private readonly http: HttpHealthIndicator,
|
2020-05-03 04:32:14 +02:00
|
|
|
private readonly typeorm: TypeOrmHealthIndicator,
|
2023-09-16 13:02:19 +02:00
|
|
|
private readonly config: ConfigService,
|
2020-05-03 04:32:14 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@HealthCheck()
|
2022-06-11 14:02:48 +02:00
|
|
|
async check(): Promise<HealthCheckResult> {
|
|
|
|
|
const health = await this.health.check([
|
2020-05-03 04:32:14 +02:00
|
|
|
() =>
|
2021-06-22 20:43:06 +02:00
|
|
|
this.http.pingCheck(
|
2020-05-03 04:32:14 +02:00
|
|
|
"spotify-web",
|
2023-09-10 20:59:58 +02:00
|
|
|
this.config.get<string>("SPOTIFY_WEB_API_URL"),
|
|
|
|
|
{
|
|
|
|
|
validateStatus: () => true,
|
2023-09-16 13:02:19 +02:00
|
|
|
}, // Successful as long as we get a valid HTTP response back }
|
2020-05-03 04:32:14 +02:00
|
|
|
),
|
|
|
|
|
() => this.typeorm.pingCheck("db"),
|
|
|
|
|
]);
|
2022-06-11 14:02:48 +02:00
|
|
|
|
|
|
|
|
configureScope((scope: Scope) => {
|
2022-06-11 18:26:46 +02:00
|
|
|
scope.setContext("health", {
|
|
|
|
|
status: health.status,
|
|
|
|
|
info: health.info,
|
|
|
|
|
error: health.error,
|
|
|
|
|
});
|
2022-06-11 14:02:48 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return health;
|
2020-05-03 04:32:14 +02:00
|
|
|
}
|
|
|
|
|
}
|