From cd05db0df0ef3a82769562dbd3650ce8926363f1 Mon Sep 17 00:00:00 2001 From: "Lennie S." Date: Sun, 12 Apr 2026 00:42:14 +0000 Subject: [PATCH] Add /health endpoint with DB connectivity check --- main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.py b/main.py index 95966fb..38870d9 100644 --- a/main.py +++ b/main.py @@ -107,6 +107,17 @@ class ListWithItems(ListResponse): def read_root(): return {"message": "Shopping List API"} +@app.get("/health", tags=["meta"]) +def health_check(): + conn = get_db() + try: + conn.execute("SELECT 1").fetchone() + conn.close() + return {"status": "ok"} + except Exception as e: + conn.close() + return {"status": "error", "detail": str(e)}, 503 + @app.post("/products", response_model=ProductResponse, status_code=201, tags=["products"]) def create_product(product: Product): conn = get_db()