Files
vps_web/config.py
ddrwode 4210e0d70a 哈哈
2026-02-10 17:54:22 +08:00

44 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""应用配置"""
import os
from urllib.parse import quote_plus
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
# MySQL 连接(可通过环境变量覆盖)
DB_HOST = os.environ.get("DB_HOST") or "199.168.137.123"
DB_PORT = os.environ.get("DB_PORT") or "3309"
DB_USER = os.environ.get("DB_USER") or "vps"
DB_NAME = os.environ.get("DB_NAME") or "vps"
DB_PASSWORD = os.environ.get("DB_PASSWORD") or "435Y4fPrZxT86wNx"
def _mysql_uri():
password = quote_plus(DB_PASSWORD)
return f"mysql+pymysql://{DB_USER}:{password}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset=utf8mb4"
class Config:
SECRET_KEY = os.environ.get("SECRET_KEY") or "dev-secret-change-in-production"
ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD") or "admin123"
# 优先使用 DATABASE_URL否则使用 MySQL
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or _mysql_uri()
SQLALCHEMY_TRACK_MODIFICATIONS = False
SITE_URL = os.environ.get("SITE_URL") or "https://vps.ddrwode.cn"
SITE_NAME = os.environ.get("SITE_NAME") or "云价眼"
PREFERRED_URL_SCHEME = "https"
SEND_FILE_MAX_AGE_DEFAULT = int(os.environ.get("STATIC_CACHE_SECONDS") or "604800")
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = os.environ.get("SESSION_COOKIE_SAMESITE") or "Lax"
SESSION_COOKIE_SECURE = (
os.environ.get("SESSION_COOKIE_SECURE")
or ("1" if (os.environ.get("FLASK_ENV") or "").lower() == "production" else "0")
) == "1"
# 兼容直接 from config import XXX
SECRET_KEY = Config.SECRET_KEY
ADMIN_PASSWORD = Config.ADMIN_PASSWORD
SITE_URL = Config.SITE_URL
SITE_NAME = Config.SITE_NAME