first commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -23,14 +23,14 @@ class Config:
|
||||
|
||||
# OpenAI兼容API配置
|
||||
LLM_API_URL = os.environ.get('LLM_API_URL') or 'https://api.deepseek.com/v1'
|
||||
LLM_API_KEY = os.environ.get('LLM_API_KEY') or 'sk-your-api-key-here'
|
||||
LLM_API_KEY = os.environ.get('LLM_API_KEY')
|
||||
|
||||
# 微信小程序配置
|
||||
WX_APPID = os.environ.get('WX_APPID') or 'wx-your-appid-here'
|
||||
WX_SECRET = os.environ.get('WX_SECRET') or 'your-wx-secret-here'
|
||||
|
||||
# 跨域配置
|
||||
CORS_ORIGINS = os.environ.get('CORS_ORIGINS', '*').split(',')
|
||||
WX_APPID = os.environ.get('WX_APPID')
|
||||
WX_SECRET = os.environ.get('WX_SECRET')
|
||||
|
||||
# 跨域配置 - 默认值在具体环境配置中设置
|
||||
CORS_ORIGINS = os.environ.get('CORS_ORIGINS', '').split(',')
|
||||
|
||||
# 日志配置
|
||||
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
|
||||
|
||||
@@ -12,6 +12,22 @@ class DevelopmentConfig(Config):
|
||||
super().__init__()
|
||||
if not self.SQLALCHEMY_DATABASE_URI:
|
||||
self.SQLALCHEMY_DATABASE_URI = 'sqlite:///dev.db'
|
||||
|
||||
# 开发环境API配置(如果未设置,使用示例值并给出警告)
|
||||
if not self.LLM_API_KEY:
|
||||
self.LLM_API_KEY = 'sk-dev-example-api-key'
|
||||
import warnings
|
||||
warnings.warn("LLM_API_KEY not set, using development example key")
|
||||
|
||||
if not self.WX_APPID:
|
||||
self.WX_APPID = 'wx-dev-example-appid'
|
||||
|
||||
if not self.WX_SECRET:
|
||||
self.WX_SECRET = 'wx-dev-example-secret'
|
||||
|
||||
# 开发环境CORS配置(如果没有设置,使用开发默认值)
|
||||
if not self.CORS_ORIGINS or self.CORS_ORIGINS == ['']:
|
||||
self.CORS_ORIGINS = ['http://localhost:3000', 'http://127.0.0.1:3000', '*']
|
||||
|
||||
# 开发环境日志配置
|
||||
LOG_LEVEL = 'DEBUG'
|
||||
|
||||
@@ -7,7 +7,27 @@ class ProductionConfig(Config):
|
||||
"""
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# 生产环境必须设置的关键配置检查
|
||||
required_configs = [
|
||||
('SECRET_KEY', self.SECRET_KEY),
|
||||
('LLM_API_KEY', self.LLM_API_KEY),
|
||||
('WX_APPID', self.WX_APPID),
|
||||
('WX_SECRET', self.WX_SECRET),
|
||||
('SQLALCHEMY_DATABASE_URI', self.SQLALCHEMY_DATABASE_URI)
|
||||
]
|
||||
|
||||
for name, value in required_configs:
|
||||
if not value:
|
||||
raise ValueError(f"生产环境必须设置{name}环境变量")
|
||||
|
||||
# 生产环境CORS配置检查(在父类中已经设置)
|
||||
if not self.CORS_ORIGINS or self.CORS_ORIGINS == ['']:
|
||||
raise ValueError("生产环境必须设置CORS_ORIGINS环境变量,指定允许的域名")
|
||||
|
||||
# 生产环境日志配置
|
||||
LOG_LEVEL = 'WARNING'
|
||||
LOG_FILE = 'logs/production.log'
|
||||
@@ -31,8 +51,8 @@ class ProductionConfig(Config):
|
||||
# 生产环境跨域配置(需要设置具体的域名)
|
||||
CORS_ORIGINS = os.environ.get('CORS_ORIGINS', '').split(',')
|
||||
if not CORS_ORIGINS or CORS_ORIGINS == ['']:
|
||||
# 如果没有设置,使用默认值而不是抛出异常
|
||||
CORS_ORIGINS = ['https://yourdomain.com']
|
||||
# 生产环境必须设置CORS域名
|
||||
raise ValueError("生产环境必须设置CORS_ORIGINS环境变量,指定允许的域名")
|
||||
|
||||
# 生产环境性能配置
|
||||
SQLALCHEMY_ENGINE_OPTIONS = {
|
||||
|
||||
Reference in New Issue
Block a user