Spaces:
Running
Running
File size: 875 Bytes
1b542dc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import { Request, Response } from "express";
import { redis } from "../../infrastructure/redis/redis-client";
import { db } from "../../infrastructure/db/db";
import { sql } from "drizzle-orm";
export async function healthCheck(req: Request, res: Response) {
const health = {
uptime: process.uptime(),
message: "OK",
timestamp: Date.now(),
services: {
redis: "down",
database: "down",
},
};
try {
await redis.ping();
health.services.redis = "up";
} catch (error) {
console.error("Redis health check failed:", error);
health.message = "ERROR";
}
try {
await db.execute(sql`SELECT 1`);
health.services.database = "up";
} catch (error) {
console.error("Database health check failed:", error);
health.message = "ERROR";
}
return res.status(health.message === "OK" ? 200 : 503).json(health);
}
|