Add health check and dev script

This commit is contained in:
Will H
2024-07-05 10:10:08 +12:00
parent a4ec2dac6c
commit 66773dfaca
4 changed files with 39 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import { MailModule } from './integrations/mail/mail.module';
import { QueueModule } from './integrations/queue/queue.module';
import { StaticModule } from './integrations/static/static.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { HealthModule } from './integrations/health/health.module';
@Module({
imports: [
@ -21,6 +22,7 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
WsModule,
QueueModule,
StaticModule,
HealthModule,
StorageModule.forRootAsync({
imports: [EnvironmentModule],
}),

View File

@ -0,0 +1,26 @@
import { KyselyDB } from '@docmost/db/types/kysely.types';
import {
Controller,
Get,
HttpCode,
HttpStatus,
InternalServerErrorException,
Post,
} from '@nestjs/common';
import { sql } from 'kysely';
import { InjectKysely } from 'nestjs-kysely';
@Controller()
export class HealthController {
constructor(@InjectKysely() private readonly db: KyselyDB) {}
@Get('health')
@HttpCode(HttpStatus.OK)
async health() {
try {
await sql`SELECT 1=1`.execute(this.db);
} catch (error) {
throw new InternalServerErrorException('Health check failed');
}
}
}

View File

@ -0,0 +1,8 @@
import { Global, Module } from '@nestjs/common';
import { HealthController } from './health.controller';
@Global()
@Module({
controllers: [HealthController],
})
export class HealthModule {}