refactor: 重组配置文件到 config 目录
- 创建 backend/config/ 目录统一管理配置文件 - 移动 config.yaml 到 config/config.yaml - 新增 config.dev.yaml 开发环境配置(debug 日志、关闭限流) - 新增 config.prod.yaml 生产环境配置(info 日志、启用限流、严格 CORS) - 更新配置加载逻辑,优先从 config/ 目录读取,兼容旧路径 - 更新 .gitignore,仅排除 .env,配置文件纳入版本控制
This commit is contained in:
55
backend/config/config.dev.yaml
Normal file
55
backend/config/config.dev.yaml
Normal file
@@ -0,0 +1,55 @@
|
||||
# CamTalk 开发环境配置
|
||||
# 通过 APP_ENV=dev 加载此文件,覆盖 config.yaml 中的配置
|
||||
|
||||
server:
|
||||
host: "0.0.0.0"
|
||||
port: 8080
|
||||
heartbeat_interval: 30
|
||||
heartbeat_timeout: 60
|
||||
allowed_origins: [] # 开发环境允许所有来源
|
||||
|
||||
session:
|
||||
ttl: 30 # 开发环境会话较短,方便测试过期逻辑
|
||||
max_history: 20
|
||||
|
||||
ai:
|
||||
stt:
|
||||
timeout: 10 # 开发环境超时较长,方便调试
|
||||
http_client_timeout: 30
|
||||
llm:
|
||||
timeout: 60 # 开发环境 LLM 超时较长
|
||||
http_client_timeout: 120
|
||||
tts:
|
||||
timeout: 10
|
||||
http_client_timeout: 30
|
||||
|
||||
storage:
|
||||
redis:
|
||||
enabled: true # 开发环境启用 Redis,测试三级存储
|
||||
persistence:
|
||||
enabled: true # 开发环境启用持久化
|
||||
|
||||
redis:
|
||||
addr: "localhost:6379" # 本地 Redis
|
||||
password: ""
|
||||
db: 0
|
||||
|
||||
auth:
|
||||
access_ttl: 120 # 开发环境 Access Token 2 小时,方便调试
|
||||
refresh_ttl: 10080 # 7 天
|
||||
|
||||
ratelimit:
|
||||
enabled: false # 开发环境关闭限流,方便测试
|
||||
query:
|
||||
capacity: 10
|
||||
rate: 0.2
|
||||
login:
|
||||
capacity: 5
|
||||
rate: 0.1
|
||||
register:
|
||||
capacity: 3
|
||||
rate: 0.05
|
||||
|
||||
log:
|
||||
level: debug # 开发环境 debug 日志
|
||||
format: console # 控制台格式,易读
|
||||
74
backend/config/config.prod.yaml
Normal file
74
backend/config/config.prod.yaml
Normal file
@@ -0,0 +1,74 @@
|
||||
# CamTalk 生产环境配置
|
||||
# 通过 APP_ENV=prod 加载此文件,覆盖 config.yaml 中的配置
|
||||
|
||||
server:
|
||||
host: "0.0.0.0"
|
||||
port: 8080
|
||||
read_timeout: 30
|
||||
write_timeout: 30
|
||||
shutdown_timeout: 15 # 生产环境优雅关闭时间稍长
|
||||
heartbeat_interval: 30
|
||||
heartbeat_timeout: 60
|
||||
allowed_origins: # 生产环境严格 CORS 白名单
|
||||
- "https://camtalk.example.com"
|
||||
- "https://www.camtalk.example.com"
|
||||
|
||||
session:
|
||||
ttl: 60 # 生产环境会话 1 小时
|
||||
max_history: 20
|
||||
|
||||
ai:
|
||||
stt:
|
||||
provider: mimo # 生产环境推荐 MiMo,性价比高
|
||||
model: mimo-v2.5-asr
|
||||
endpoint: "https://api.xiaomimimo.com/v1"
|
||||
timeout: 5 # 生产环境严格超时控制
|
||||
http_client_timeout: 30
|
||||
llm:
|
||||
provider: dashscope # 生产环境推荐通义千问,稳定性好
|
||||
model: qwen3-vl-plus
|
||||
endpoint: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
timeout: 30
|
||||
http_client_timeout: 60
|
||||
tts:
|
||||
provider: mimo # 生产环境推荐 MiMo TTS
|
||||
model: mimo-v2.5-tts
|
||||
voice: mimo_default
|
||||
speed: 1.0
|
||||
endpoint: "https://token-plan-cn.xiaomimimo.com/v1"
|
||||
timeout: 5
|
||||
http_client_timeout: 30
|
||||
output_format: mp3
|
||||
sample_rate: 24000
|
||||
|
||||
storage:
|
||||
redis:
|
||||
enabled: true # 生产环境必须启用 Redis
|
||||
persistence:
|
||||
enabled: true # 生产环境必须启用持久化
|
||||
driver: postgres
|
||||
|
||||
redis:
|
||||
addr: "redis:6379" # Docker Compose 内部服务名
|
||||
password: "" # 密码通过 CAMTALK_REDIS_PASSWORD 环境变量设置
|
||||
db: 0
|
||||
|
||||
auth:
|
||||
access_ttl: 120 # 生产环境 Access Token 2 小时
|
||||
refresh_ttl: 10080 # Refresh Token 7 天
|
||||
|
||||
ratelimit:
|
||||
enabled: true # 生产环境启用限流
|
||||
query:
|
||||
capacity: 10 # 允许突发 10 个请求
|
||||
rate: 0.2 # 每 5 秒恢复 1 个令牌
|
||||
login:
|
||||
capacity: 5 # 防暴力破解
|
||||
rate: 0.1 # 每 10 秒恢复 1 次
|
||||
register:
|
||||
capacity: 3 # 防批量注册
|
||||
rate: 0.05 # 每 20 秒恢复 1 次
|
||||
|
||||
log:
|
||||
level: info # 生产环境 info 级别
|
||||
format: json # JSON 格式,便于日志收集和分析
|
||||
80
backend/config/config.yaml
Normal file
80
backend/config/config.yaml
Normal file
@@ -0,0 +1,80 @@
|
||||
# CamTalk 后端配置
|
||||
|
||||
app:
|
||||
env: dev # dev / prod,可通过 APP_ENV 环境变量覆盖
|
||||
|
||||
server:
|
||||
host: "0.0.0.0"
|
||||
port: 8080
|
||||
read_timeout: 30 # 秒
|
||||
write_timeout: 30 # 秒
|
||||
shutdown_timeout: 10 # 优雅关闭超时(秒)
|
||||
heartbeat_interval: 30 # 心跳检查间隔(秒)
|
||||
heartbeat_timeout: 60 # 心跳超时断开(秒)
|
||||
allowed_origins: [] # CORS 白名单,空=允许所有
|
||||
|
||||
session:
|
||||
ttl: 30 # 会话过期时间(分钟)
|
||||
max_history: 20 # 对话历史上限(条)
|
||||
|
||||
ai:
|
||||
stt:
|
||||
provider: mimo # mimo / deepgram
|
||||
model: mimo-v2.5-asr
|
||||
endpoint: "https://api.xiaomimimo.com/v1"
|
||||
timeout: 5 # STT 请求超时(秒)
|
||||
http_client_timeout: 30 # HTTP 客户端超时(秒)
|
||||
llm:
|
||||
provider: dashscope # dashscope / openai
|
||||
model: qwen3-vl-plus
|
||||
endpoint: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
timeout: 30 # LLM 请求超时(秒)
|
||||
http_client_timeout: 60 # HTTP 客户端超时(秒)
|
||||
tts:
|
||||
provider: mimo # mimo / openai
|
||||
model: mimo-v2.5-tts
|
||||
voice: mimo_default
|
||||
speed: 1.0
|
||||
endpoint: "https://token-plan-cn.xiaomimimo.com/v1"
|
||||
timeout: 5 # TTS 请求超时(秒)
|
||||
http_client_timeout: 30 # HTTP 客户端超时(秒)
|
||||
output_format: mp3 # 输出格式:mp3 / wav
|
||||
sample_rate: 24000 # 输出采样率
|
||||
|
||||
storage:
|
||||
# 三级存储架构:L1 内存 → L2 Redis → L3 PostgreSQL
|
||||
redis:
|
||||
enabled: true # 是否启用 Redis(L2 热数据层)
|
||||
persistence:
|
||||
enabled: true # 是否启用持久化(L3 冷数据层)
|
||||
driver: postgres # postgres
|
||||
# dsn 通过环境变量 CAMTALK_STORAGE_DSN 设置
|
||||
|
||||
redis:
|
||||
addr: "localhost:6379"
|
||||
password: ""
|
||||
db: 0
|
||||
|
||||
auth:
|
||||
# jwt_secret 通过环境变量 CAMTALK_AUTH_JWT_SECRET 设置
|
||||
access_ttl: 120 # Access Token 过期时间(分钟)
|
||||
refresh_ttl: 10080 # Refresh Token 过期时间(分钟),7 天
|
||||
|
||||
ratelimit:
|
||||
enabled: false # 是否启用限流
|
||||
# WebSocket query 消息限流(核心,控制 AI 成本)
|
||||
query:
|
||||
capacity: 10 # 突发容量:允许连续发 10 个 query
|
||||
rate: 0.2 # 填充速率:每 5 秒补充 1 个令牌
|
||||
# REST API 登录限流(防暴力破解)
|
||||
login:
|
||||
capacity: 5 # 突发容量:允许连续 5 次登录尝试
|
||||
rate: 0.1 # 填充速率:每 10 秒补充 1 次
|
||||
# REST API 注册限流
|
||||
register:
|
||||
capacity: 3 # 突发容量:允许连续 3 次注册
|
||||
rate: 0.05 # 填充速率:每 20 秒补充 1 次
|
||||
|
||||
log:
|
||||
level: info # debug / info / warn / error
|
||||
format: console # console / json
|
||||
Reference in New Issue
Block a user