Merge branch 'branch2' into sorted-fastload

This commit is contained in:
2025-11-23 12:42:35 +08:00

39
app.py
View File

@@ -66,37 +66,30 @@ def get_remote_address() -> str:
limiter = Limiter(
get_remote_address,
app=app,
# default_limits=[],
# storage_uri="memory://",
# Redis
storage_uri=os.environ.get("REDIS_URI", "redis://127.0.0.1:6379/"),
# Redis cluster
# storage_uri="redis+cluster://localhost:7000,localhost:7001,localhost:70002",
# Memcached
# storage_uri="memcached://localhost:11211",
# Memcached Cluster
# storage_uri="memcached://localhost:11211,localhost:11212,localhost:11213",
# MongoDB
# storage_uri="mongodb://localhost:27017",
# Etcd
# storage_uri="etcd://localhost:2379",
strategy="fixed-window", # or "moving-window"
strategy="fixed-window",
storage_uri=os.environ.get("REDIS_URI") or "memory://",
)
client = MongoClient(host=os.environ.get("TAIKO_WEB_MONGO_HOST") or take_config('MONGO', required=True)['host'])
basedir = take_config('BASEDIR') or '/'
app.secret_key = take_config('SECRET_KEY') or 'change-me'
app.config['SESSION_TYPE'] = 'redis'
redis_config = take_config('REDIS', required=True)
redis_config['CACHE_REDIS_HOST'] = os.environ.get("TAIKO_WEB_REDIS_HOST") or redis_config['CACHE_REDIS_HOST']
app.config['SESSION_REDIS'] = Redis(
host=redis_config['CACHE_REDIS_HOST'],
port=redis_config['CACHE_REDIS_PORT'],
password=redis_config['CACHE_REDIS_PASSWORD'],
db=redis_config['CACHE_REDIS_DB']
)
app.cache = Cache(app, config=redis_config)
try:
_r = Redis(
host=redis_config['CACHE_REDIS_HOST'],
port=redis_config['CACHE_REDIS_PORT'],
password=redis_config['CACHE_REDIS_PASSWORD'],
db=redis_config['CACHE_REDIS_DB']
)
_r.ping()
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_REDIS'] = _r
app.cache = Cache(app, config=redis_config)
except Exception:
app.config['SESSION_TYPE'] = 'filesystem'
app.cache = Cache(app, config={'CACHE_TYPE': 'SimpleCache'})
sess = Session()
sess.init_app(app)
#csrf = CSRFProtect(app)