Spaces:
Running
Running
Download src/api/controller/health-controller.ts from risenetup/chess-monolith: direct link, hf CLI and curl.
- Browser
- Download file 875 Bytes
-
https://huggingface.co/spaces/risenetup/chess-monolith/resolve/main/src/api/controller/health-controller.ts
- Command line
-
hf download hf://spaces/risenetup/chess-monolith/src/api/controller/health-controller.ts
-
curl -L -o health-controller.ts https://huggingface.co/spaces/risenetup/chess-monolith/resolve/main/src/api/controller/health-controller.ts
875 Bytes
| 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); | |
| } | |