llm_host / middleware.py
eli02's picture
Add FastAPI application with WebSocket support and authentication
546720a
raw
history blame
552 Bytes
from fastapi import Request
from slowapi import Limiter
from slowapi.util import get_remote_address
from slowapi.middleware import SlowAPIMiddleware
limiter = Limiter(key_func=get_remote_address)
async def log_requests(request: Request, call_next):
print(f"Request: {request.method} {request.url}")
response = await call_next(request)
print(f"Response: {response.status_code}")
return response
# Apply the rate limiter middleware
def setup_rate_limiter(app):
app.state.limiter = limiter
app.add_middleware(SlowAPIMiddleware)