Rate limiting
Build and Push Docker Image / build-and-push (push) Successful in 18s

This commit is contained in:
ciomek committed 2026-08-17 20:44:10 +02:00
1 parent 92b701fd59
commit cb01e1bcf0
4 files changed
+93 -3

No files matched your search

+8 -1
View File
@@ -1,6 +1,8 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.middleware.cors import CORSMiddleware
@@ -14,10 +16,15 @@ async def lifespan(app: FastAPI):
app.state.mqtt_manager = MQTTManager.setup_and_start()
yield
docs_url = "docs" if settings.web.show_docs else None
limiter = Limiter(key_func=lambda request: request.client.host)
docs_url = "/docs" if settings.web.show_docs else None
app = FastAPI(lifespan=lifespan, docs_url=docs_url)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
app.add_middleware(
AuthenticationMiddleware,
backend=JWTAuthBackend(),