improve healthcheck slightly
This commit is contained in:
@@ -69,19 +69,33 @@ export function generateRequestBodies() {
|
|||||||
* @swagger
|
* @swagger
|
||||||
* /api/healthcheck:
|
* /api/healthcheck:
|
||||||
* get:
|
* get:
|
||||||
* summary: Check if the API is running
|
* summary: Check if the API is running and if the database is reachable
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: API is healthy
|
* description: API and DB are healthy
|
||||||
* content:
|
* content:
|
||||||
* application/json:
|
* application/json:
|
||||||
* example:
|
* example:
|
||||||
* status: "ok"
|
* status: "ok"
|
||||||
|
* db: "ok"
|
||||||
|
* 500:
|
||||||
|
* description: Database unreachable
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* example:
|
||||||
|
* status: "error"
|
||||||
|
* db: "down"
|
||||||
*/
|
*/
|
||||||
router.get("/healthcheck", (req, res) => {
|
router.get("/healthcheck", async (req, res) => {
|
||||||
res.json({ status: "ok" })
|
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
|
* @swagger
|
||||||
* /api/users:
|
* /api/users:
|
||||||
|
|||||||
Reference in New Issue
Block a user