update pay ui
This commit is contained in:
34
app_vx.py
34
app_vx.py
@@ -597,14 +597,36 @@ JWT_SECRET_KEY = 'vfllmgreat33818!' # 请修改为安全的密钥
|
||||
JWT_ALGORITHM = 'HS256'
|
||||
JWT_EXPIRATION_HOURS = 24 * 7 # Token有效期7天
|
||||
|
||||
# Session 配置 - 使用文件系统存储(替代 Redis)
|
||||
app.config['SESSION_TYPE'] = 'filesystem'
|
||||
app.config['SESSION_FILE_DIR'] = os.path.join(os.path.dirname(__file__), 'flask_session')
|
||||
# Session 配置
|
||||
# 优先使用 Redis(支持多 worker 共享),否则回退到文件系统
|
||||
_REDIS_URL = os.environ.get('REDIS_URL', 'redis://localhost:6379/0')
|
||||
_USE_REDIS_SESSION = os.environ.get('USE_REDIS_SESSION', 'true').lower() == 'true'
|
||||
|
||||
try:
|
||||
if _USE_REDIS_SESSION:
|
||||
import redis
|
||||
# 测试 Redis 连接
|
||||
_redis_client = redis.from_url(_REDIS_URL)
|
||||
_redis_client.ping()
|
||||
|
||||
app.config['SESSION_TYPE'] = 'redis'
|
||||
app.config['SESSION_REDIS'] = _redis_client
|
||||
app.config['SESSION_KEY_PREFIX'] = 'vf_session:'
|
||||
logger.info(f"✅ Session 存储: Redis ({_REDIS_URL})")
|
||||
else:
|
||||
raise Exception("Redis session disabled by config")
|
||||
except Exception as e:
|
||||
# Redis 不可用,回退到文件系统
|
||||
logger.warning(f"⚠️ Redis 不可用 ({e}),使用文件系统 session(多 worker 模式下可能不稳定)")
|
||||
app.config['SESSION_TYPE'] = 'filesystem'
|
||||
app.config['SESSION_FILE_DIR'] = os.path.join(os.path.dirname(__file__), 'flask_session')
|
||||
os.makedirs(app.config['SESSION_FILE_DIR'], exist_ok=True)
|
||||
|
||||
app.config['SESSION_PERMANENT'] = True
|
||||
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7) # Session 有效期 7 天
|
||||
|
||||
# 确保 session 目录存在
|
||||
os.makedirs(app.config['SESSION_FILE_DIR'], exist_ok=True)
|
||||
app.config['SESSION_COOKIE_SECURE'] = False # 生产环境 HTTPS 时设为 True
|
||||
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
||||
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
||||
|
||||
# Cache directory setup
|
||||
CACHE_DIR = Path('cache')
|
||||
|
||||
Reference in New Issue
Block a user