app.bettersight.io/backend/extensions.py

15 lines
660 B
Python

import os
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
# RATELIMIT_STORAGE_URI lets tests point the limiter at an in-process
# memory:// backend instead of the production Redis instance — Flask-
# Limiter reads its storage_uri/enabled flags once at init_app() time,
# so this must be set via env var before app.py imports this module,
# not by mutating app.config afterwards (see tests/conftest.py).
limiter = Limiter(
key_func=get_remote_address,
storage_uri=os.getenv('RATELIMIT_STORAGE_URI', os.getenv('REDIS_URL', 'redis://bettersight-redis:6379')),
default_limits=['200 per hour', '30 per minute'],
)