Add /health endpoint with DB connectivity check
This commit is contained in:
11
main.py
11
main.py
@@ -107,6 +107,17 @@ class ListWithItems(ListResponse):
|
|||||||
def read_root():
|
def read_root():
|
||||||
return {"message": "Shopping List API"}
|
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"])
|
@app.post("/products", response_model=ProductResponse, status_code=201, tags=["products"])
|
||||||
def create_product(product: Product):
|
def create_product(product: Product):
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
|
|||||||
Reference in New Issue
Block a user