From 6566cbe3a0ff590999bbb2fd796a433fe881548b Mon Sep 17 00:00:00 2001 From: Username Date: Thu, 8 Jan 2026 19:14:33 +0100 Subject: [PATCH] exempt /health from rate limiting Health check endpoint was being rate-limited (60/hour), causing container health checks (every 30s = 120/hour) to fail with 429. Uses flask-limiter's request_filter to bypass rate limiting for the health endpoint, supporting URL_PREFIX configuration. --- app/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 384fb20..83fbbe4 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -226,12 +226,20 @@ def setup_rate_limiting(app: Flask) -> None: from flask_limiter import Limiter from flask_limiter.util import get_remote_address + def health_endpoint_filter() -> bool: + """Exempt health check endpoint from rate limiting.""" + # Get configured URL prefix (e.g., "/paste") + prefix = app.config.get("URL_PREFIX", "") + health_path = f"{prefix}/health" if prefix else "/health" + return request.path == health_path + limiter = Limiter( key_func=get_remote_address, app=app, default_limits=["200 per day", "60 per hour"], storage_uri="memory://", strategy="fixed-window", + request_filter=health_endpoint_filter, ) # Store limiter on app for use in routes