feat: add HealthController with database connection check
Introduced a HealthController to verify application status. Includes an endpoint to check database connectivity and returns health status with a timestamp.
This commit is contained in:
28
backend/src/health.controller.ts
Normal file
28
backend/src/health.controller.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Controller, Get } from "@nestjs/common";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { DatabaseService } from "./database/database.service";
|
||||
|
||||
@Controller("health")
|
||||
export class HealthController {
|
||||
constructor(private readonly databaseService: DatabaseService) {}
|
||||
|
||||
@Get()
|
||||
async check() {
|
||||
try {
|
||||
// Check database connection
|
||||
await this.databaseService.db.execute(sql`SELECT 1`);
|
||||
return {
|
||||
status: "ok",
|
||||
database: "connected",
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: "error",
|
||||
database: "disconnected",
|
||||
message: error.message,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user