Stealth CORS with Origin Reflection and Reliable Logging
This commit is contained in:
12
app/main.py
12
app/main.py
@@ -3,6 +3,12 @@ from fastapi import FastAPI, Request
|
||||
from slowapi import _rate_limit_exceeded_handler
|
||||
from slowapi.errors import RateLimitExceeded
|
||||
|
||||
import logging
|
||||
|
||||
# Set up logging to stdout
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger("ai_gateway")
|
||||
|
||||
from app.api.router import api_router
|
||||
from app.core.config import settings
|
||||
from app.core.limiter import limiter
|
||||
@@ -34,10 +40,10 @@ def create_application() -> FastAPI:
|
||||
# Debug Logger Middleware
|
||||
@application.middleware("http")
|
||||
async def log_requests(request: Request, call_next):
|
||||
print(f"DEBUG: Incoming {request.method} {request.url}")
|
||||
print(f"DEBUG: Origin: {request.headers.get('origin')}")
|
||||
logger.info(f"DEBUG: Incoming {request.method} {request.url}")
|
||||
logger.info(f"DEBUG: Origin: {request.headers.get('origin')}")
|
||||
response = await call_next(request)
|
||||
print(f"DEBUG: Status Code: {response.status_code}")
|
||||
logger.info(f"DEBUG: Status Code: {response.status_code}")
|
||||
return response
|
||||
|
||||
# Set up Rate Limiter (CORS is handled by Caddy at the edge)
|
||||
|
||||
Reference in New Issue
Block a user