Skip to content

Commit

Permalink
Add health check and dev script
Browse files Browse the repository at this point in the history
  • Loading branch information
will2hew committed Jul 4, 2024
1 parent a4ec2da commit 66773df
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -21,6 +22,7 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
WsModule,
QueueModule,
StaticModule,
HealthModule,
StorageModule.forRootAsync({
imports: [EnvironmentModule],
}),
Expand Down
26 changes: 26 additions & 0 deletions apps/server/src/integrations/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
8 changes: 8 additions & 0 deletions apps/server/src/integrations/health/health.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Global, Module } from '@nestjs/common';
import { HealthController } from './health.controller';

@Global()
@Module({
controllers: [HealthController],
})
export class HealthModule {}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"client:dev": "nx run client:dev",
"server:dev": "nx run server:start:dev",
"server:start": "nx run server:start:prod",
"email:dev": "nx run @docmost/transactional:dev"
"email:dev": "nx run @docmost/transactional:dev",
"dev": "pnpm concurrently -n \"frontend,backend\" -c \"cyan,green\" \"pnpm run client:dev\" \"pnpm run server:dev\""
},
"dependencies": {
"@docmost/editor-ext": "workspace:*",
Expand Down Expand Up @@ -66,6 +67,7 @@
"@nx/js": "19.3.2",
"@types/uuid": "^10.0.0",
"nx": "19.3.2",
"concurrently": "^8.2.2",
"tsx": "^4.15.7"
},
"workspaces": {
Expand Down

0 comments on commit 66773df

Please sign in to comment.