Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import {
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { InjectConnection } from '@nestjs/mongoose';
import { Connection } from 'mongoose';

@ApiTags('health')
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
constructor(
private readonly appService: AppService,
@InjectConnection() private readonly mongoConnection: Connection,
) {}

@ApiExcludeEndpoint(true)
@Get()
Expand Down Expand Up @@ -47,4 +53,35 @@ export class AppController {
message: 'content ServiceApp is working',
};
}

@ApiOperation({
summary: 'Deep health check',
description: 'Returns service health including dependency status',
})
@ApiResponse({
status: 200,
description: 'Health status with dependency checks',
schema: {
type: 'object',
properties: {
status: { type: 'string', example: 'ok' },
services: {
type: 'object',
properties: { mongodb: { type: 'boolean' } },
},
uptime: { type: 'number' },
timestamp: { type: 'string' },
},
},
})
@Get('/health')
deepHealth() {
const mongoOk = this.mongoConnection.readyState === 1;
return {
status: mongoOk ? 'ok' : 'degraded',
services: { mongodb: mongoOk },
uptime: process.uptime(),
timestamp: new Date().toISOString(),
};
}
}