xxx
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
import urllib.parse
|
||||
from typing import Dict, Any
|
||||
from typing import Dict, Any, List
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
@@ -75,6 +75,11 @@ class Settings:
|
||||
self.REDIS_PASSWORD = os.getenv("REDIS_PASSWORD", "")
|
||||
self.REDIS_DB = int(os.getenv("REDIS_DB", "0"))
|
||||
|
||||
# CORS 白名单(逗号分隔,默认允许本机开发地址)
|
||||
self.CORS_ORIGINS = self._parse_cors_origins(
|
||||
os.getenv("CORS_ORIGINS", "")
|
||||
)
|
||||
|
||||
# LLM 增强分析配置(可选)
|
||||
self.LLM_ENABLED = os.getenv("LLM_ENABLED", "false").lower() == "true"
|
||||
self.LLM_API_URL = os.getenv("LLM_API_URL", "https://api.openai.com/v1")
|
||||
@@ -95,5 +100,14 @@ class Settings:
|
||||
def allowed_extensions_set(self) -> set:
|
||||
return set(ext.strip() for ext in self.ALLOWED_EXTENSIONS.split(","))
|
||||
|
||||
@staticmethod
|
||||
def _parse_cors_origins(raw: str) -> List[str]:
|
||||
"""解析 CORS_ORIGINS 环境变量,逗号分隔。
|
||||
为空时返回空列表(由 app_factory 决定是否降级为 ['*'])。
|
||||
"""
|
||||
if not raw or not raw.strip():
|
||||
return []
|
||||
return [o.strip().rstrip("/") for o in raw.split(",") if o.strip()]
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
||||
Reference in New Issue
Block a user