From 88905a2684b173b7ff2cb85ad502a285880589ed Mon Sep 17 00:00:00 2001 From: johnpccd Date: Sat, 24 May 2025 15:07:46 +0200 Subject: [PATCH] add /health endpoint --- main.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.py b/main.py index 9e46509..18feb08 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from fastapi.openapi.docs import get_swagger_ui_html from fastapi.openapi.utils import get_openapi +import time # Import API routers from src.api.v1 import teams, users, images, auth, search @@ -29,6 +30,23 @@ app = FastAPI( openapi_url="/api/v1/openapi.json" ) +# Add request logging middleware +@app.middleware("http") +async def log_requests(request: Request, call_next): + start_time = time.time() + + # Log incoming request details + logger.info(f"Incoming request: {request.method} {request.url}") + logger.info(f"Headers: {dict(request.headers)}") + logger.info(f"Client: {request.client}") + + response = await call_next(request) + + process_time = time.time() - start_time + logger.info(f"Request completed in {process_time:.4f}s with status {response.status_code}") + + return response + # Connect to database try: db.connect_to_database() @@ -130,6 +148,11 @@ def custom_openapi(): app.openapi = custom_openapi +@app.get("/health", include_in_schema=False) +async def health_check(): + """Health check endpoint for monitoring and client connectivity tests""" + return {"status": "healthy", "message": "API is running"} + @app.get("/", include_in_schema=False) async def root(): return {"message": "Welcome to the Image Management API. Please see /docs for API documentation."}