2 Commits

27
app.py
View File

@@ -66,37 +66,30 @@ def get_remote_address() -> str:
limiter = Limiter( limiter = Limiter(
get_remote_address, get_remote_address,
app=app, app=app,
# default_limits=[], strategy="fixed-window",
# storage_uri="memory://", storage_uri=os.environ.get("REDIS_URI") or "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"
) )
client = MongoClient(host=os.environ.get("TAIKO_WEB_MONGO_HOST") or take_config('MONGO', required=True)['host']) client = MongoClient(host=os.environ.get("TAIKO_WEB_MONGO_HOST") or take_config('MONGO', required=True)['host'])
basedir = take_config('BASEDIR') or '/' basedir = take_config('BASEDIR') or '/'
app.secret_key = take_config('SECRET_KEY') or 'change-me' app.secret_key = take_config('SECRET_KEY') or 'change-me'
app.config['SESSION_TYPE'] = 'redis'
redis_config = take_config('REDIS', required=True) 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'] redis_config['CACHE_REDIS_HOST'] = os.environ.get("TAIKO_WEB_REDIS_HOST") or redis_config['CACHE_REDIS_HOST']
app.config['SESSION_REDIS'] = Redis( try:
_r = Redis(
host=redis_config['CACHE_REDIS_HOST'], host=redis_config['CACHE_REDIS_HOST'],
port=redis_config['CACHE_REDIS_PORT'], port=redis_config['CACHE_REDIS_PORT'],
password=redis_config['CACHE_REDIS_PASSWORD'], password=redis_config['CACHE_REDIS_PASSWORD'],
db=redis_config['CACHE_REDIS_DB'] 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) 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 = Session()
sess.init_app(app) sess.init_app(app)
#csrf = CSRFProtect(app) #csrf = CSRFProtect(app)