add /health endpoint
This commit is contained in:
parent
365569aa52
commit
88905a2684
23
main.py
23
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."}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user