Automated Action f44d1064ae Add request logging middleware to FastAPI application
Added RequestLoggingMiddleware that logs incoming HTTP requests with method, path, response status, and processing time using Python's built-in logging module.
2025-06-19 17:43:16 +00:00

50 lines
1.1 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.middleware.logging import RequestLoggingMiddleware
from app.api.router import api_router
app = FastAPI(
title="Todo App API",
description="A simple todo application API",
version="1.0.0",
openapi_url="/openapi.json"
)
# Add request logging middleware
app.add_middleware(RequestLoggingMiddleware)
# Configure CORS to allow all origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def root():
"""Base URL endpoint returning project information"""
return {
"title": "Todo App API",
"documentation": "/docs",
"redoc": "/redoc",
"health": "/health",
"openapi": "/openapi.json"
}
@app.get("/health")
async def health_check():
"""Health check endpoint"""
return {"status": "healthy", "message": "Todo App API is running"}
# Include API router
app.include_router(api_router, prefix="/api/v1")
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)