diff --git a/.env.dist b/.env.dist index 590641b..b98c244 100644 --- a/.env.dist +++ b/.env.dist @@ -7,6 +7,7 @@ APP_BASE_URL=https://overfast-api.tekrop.fr LOG_LEVEL=info MAX_CONCURRENT_REQUESTS=5 STATUS_PAGE_URL= +TOO_MANY_REQUESTS_RESPONSE=false # Redis REDIS_CACHING_ENABLED=true diff --git a/README.md b/README.md index 28ac4f1..196537a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ## ✨ [Live instance](https://overfast-api.tekrop.fr) -The live instance is restricted to **30 req/s** (a shared limit across all endpoints). If you require more, consider hosting your own instance on a server 👍 +The live instance is restricted to **30 req/s** per IP (a shared limit across all endpoints). If you require more, consider hosting your own instance on a server 👍 - Live instance (Redoc documentation) : https://overfast-api.tekrop.fr/ - Swagger UI : https://overfast-api.tekrop.fr/docs diff --git a/app/common/helpers.py b/app/common/helpers.py index 5d54d07..f53f7ce 100644 --- a/app/common/helpers.py +++ b/app/common/helpers.py @@ -32,6 +32,10 @@ "description": "Blizzard Server Error", }, } +if settings.too_many_requests_response: + routes_responses[status.HTTP_429_TOO_MANY_REQUESTS] = { + "description": "Rate Limit Error", + } # List of players used for testing players_ids = [ diff --git a/app/config.py b/app/config.py index 69543e9..d201118 100644 --- a/app/config.py +++ b/app/config.py @@ -45,6 +45,10 @@ class Settings(BaseSettings): # Optional, status page URL if you have any to provide status_page_url: str | None = None + # Enable this option if you're using a reverse proxy to handle rate limits + # in order to indicate HTTP 429 as possible response from the API in doc + too_many_requests_response: bool = True + ############ # REDIS CONFIGURATION ############ diff --git a/app/main.py b/app/main.py index 4847ed8..4fb019a 100644 --- a/app/main.py +++ b/app/main.py @@ -34,8 +34,14 @@ async def lifespan(_: FastAPI): # pragma: no cover reverse proxy and **Redis** for caching. Its tailored caching mechanism significantly reduces calls to Blizzard pages, ensuring swift and precise data delivery to users. -This live instance is restricted to **30 req/s** (a shared limit across all endpoints). +{ +""" +This live instance is restricted to **30 req/s** per IP (a shared limit across all endpoints). If you require more, consider hosting your own instance on a server 👍 +""" +if settings.too_many_requests_response +else "" +} In player career statistics, various conversions are applied for ease of use: - **Duration values** are converted to **seconds** (integer)