From 14ddaa39324c63135ddaca0196f0931a94f7b182 Mon Sep 17 00:00:00 2001 From: RHM Date: Thu, 11 Sep 2025 20:17:10 +0200 Subject: [PATCH] improve healthcheck slightly --- backend/src/api.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/src/api.js b/backend/src/api.js index b0d5cbb..1fa0016 100644 --- a/backend/src/api.js +++ b/backend/src/api.js @@ -69,19 +69,33 @@ export function generateRequestBodies() { * @swagger * /api/healthcheck: * get: - * summary: Check if the API is running + * summary: Check if the API is running and if the database is reachable * responses: * 200: - * description: API is healthy + * description: API and DB are healthy * content: * application/json: * example: * status: "ok" + * db: "ok" + * 500: + * description: Database unreachable + * content: + * application/json: + * example: + * status: "error" + * db: "down" */ -router.get("/healthcheck", (req, res) => { - res.json({ status: "ok" }) +router.get("/healthcheck", async (req, res) => { + try { + await pool.query("SELECT 1"); // basic DB check + res.json({ status: "ok", db: "ok" }); + } catch { + res.status(500).json({ status: "error", db: "down" }); + } }); + /** * @swagger * /api/users: