Introduced a HealthController to verify application status. Includes an endpoint to check database connectivity and returns health status with a timestamp.
29 lines
664 B
TypeScript
29 lines
664 B
TypeScript
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(),
|
|
};
|
|
}
|
|
}
|
|
}
|