Add /health endpoint with DB connectivity check
Some checks failed
CI / test (push) Successful in 54s
CI / docker-push (push) Failing after 1m56s

This commit is contained in:
Lennie S.
2026-04-12 00:42:14 +00:00
parent 9967cbc51f
commit cd05db0df0

11
main.py
View File

@@ -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()