INNER CODE UNIT · Python
rate_limit_handler
gokulapap/Reconator · backend/app/main.py:48
async def rate_limit_handler(request: Request, exc: RateLimitExceeded):
return JSONResponse({"detail": f"rate limit exceeded: {exc.detail}"}, status_code=429)
app.add_middleware(RequestIDMiddleware)
app.add_middleware(SecurityHeadersMiddleware)
app.add_middleware(RequestBodyLimitMiddleware, max_bytes=settings.max_request_body_bytes)
if settings.metrics_enabled:
app.add_middleware(PrometheusMiddleware)
origins = [o.strip() for o in settings.cors_origins.split(",") if o.strip()]
allowed_hosts = [host.strip() for host in settings.allowed_hosts.split(",") if host.strip()]
app.add_middleware(TrustedHostMiddleware, allowed_hosts=allowed_hosts or ["localhost"])
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials="*" not in origins,
allow_methods=["*"],