- Add platform infrastructure chapter to frontend-backend architecture design - Update system architecture document with 6 new infrastructure modules - Update AI onboarding guide with infrastructure overview - Link to backend/src/common/README.md for detailed usage guide Key Updates: - Storage service (LocalAdapter + OSSAdapter) - Logging system (Winston + JSON format) - Cache service (Memory + Redis) - Async job queue (Memory + Database) - Health check endpoints - Monitoring metrics - Database connection pool - Environment config management All modules support zero-code switching between local and cloud environments. Related: #Platform-Infrastructure
4.8 KiB
4.8 KiB
环境变量配置模板 (.env)
文档说明: 本文档提供完整的
.env配置模板
使用方式: 复制以下内容到backend/.env文件中,并填入真实配置值
创建日期: 2025-11-09
📋 完整配置模板
将以下内容复制到 AIclinicalresearch/backend/.env 文件:
# ================================
# 服务器配置
# ================================
PORT=3001
HOST=0.0.0.0
NODE_ENV=development
LOG_LEVEL=info
# ================================
# 数据库配置
# ================================
DATABASE_URL=postgresql://postgres:your_password@localhost:5432/ai_clinical_research
# ================================
# Redis配置
# ================================
REDIS_URL=redis://localhost:6379
# ================================
# JWT配置
# ================================
JWT_SECRET=your-secret-key-change-in-production-min-32-chars
JWT_EXPIRES_IN=7d
# ================================
# LLM API配置
# ================================
# ---------- DeepSeek (直连) ----------
DEEPSEEK_API_KEY=sk-your-deepseek-api-key
DEEPSEEK_BASE_URL=https://api.deepseek.com
# ---------- Qwen (通过阿里云DashScope) ----------
DASHSCOPE_API_KEY=sk-your-dashscope-api-key
# ---------- Gemini (可选) ----------
GEMINI_API_KEY=your-gemini-api-key
# ================================
# CloseAI配置(代理OpenAI和Claude)⭐
# ================================
# CloseAI是一个API代理平台,提供稳定的OpenAI和Claude访问
# 官网:https://platform.openai-proxy.org
# 统一API Key(同时用于OpenAI和Claude)
CLOSEAI_API_KEY=sk-your-closeai-api-key
# OpenAI端点
CLOSEAI_OPENAI_BASE_URL=https://api.openai-proxy.org/v1
# Claude端点
CLOSEAI_CLAUDE_BASE_URL=https://api.openai-proxy.org/anthropic
# 支持的模型:
# - OpenAI: gpt-5-pro, gpt-4-turbo-preview, gpt-3.5-turbo
# - Claude: claude-sonnet-4-5-20250929, claude-3-5-sonnet-20241022
# ================================
# Dify配置(知识库RAG引擎)
# ================================
DIFY_API_KEY=app-your-dify-api-key
DIFY_API_URL=http://localhost/v1
# ================================
# 文件上传配置
# ================================
UPLOAD_MAX_SIZE=10485760
UPLOAD_DIR=./uploads
# ================================
# CORS配置
# ================================
CORS_ORIGIN=http://localhost:5173
# ================================
# 注意事项
# ================================
# 1. 请将 your-* 占位符替换为真实的配置值
# 2. .env 文件包含敏感信息,不要提交到 git 仓库
# 3. 生产环境请使用强密码和独立的 API Key
# 4. JWT_SECRET 建议使用 32 位以上随机字符串
🔒 当前真实配置(仅供参考)
CloseAI配置(已配置)⭐
CLOSEAI_API_KEY=sk-cu0iepbXYGGx2jc7BqP6ogtSWmP6fk918qV3RUdtGC3Edlpo
CLOSEAI_OPENAI_BASE_URL=https://api.openai-proxy.org/v1
CLOSEAI_CLAUDE_BASE_URL=https://api.openai-proxy.org/anthropic
可用模型:
- OpenAI:
gpt-5-pro - Claude:
claude-sonnet-4-5-20250929
📝 配置步骤
1. 创建 .env 文件
cd AIclinicalresearch/backend
# 复制模板
copy .env.example .env # Windows
# 或
cp .env.example .env # Linux/Mac
2. 填入真实配置
打开 backend/.env 文件,替换占位符:
必须配置:
DATABASE_URL- 数据库连接DEEPSEEK_API_KEY- DeepSeek API(主力模型)CLOSEAI_API_KEY- CloseAI API(OpenAI+Claude)
可选配置:
DASHSCOPE_API_KEY- Qwen模型DIFY_API_KEY- 知识库RAGJWT_SECRET- 生产环境必须修改
3. 验证配置
# 启动后端服务
cd backend
npm run dev
# 检查日志,确认没有 API Key 警告
⚠️ 安全提醒
不要提交到Git
确认 .gitignore 包含:
# 环境变量文件
.env
.env.local
.env.*.local
API Key安全
- 定期轮换: 每3个月更换一次API Key
- 权限最小化: 只授予必要的权限
- 独立密钥: 开发/测试/生产使用不同的Key
- 监控使用: 定期检查API调用量和费用
泄露应急
如果API Key不慎泄露:
- 立即在服务商后台禁用/删除该Key
- 生成新的API Key
- 更新
.env文件 - 重启服务
🔍 配置验证清单
部署前请确认:
- ✅ DATABASE_URL 配置正确且可连接
- ✅ DEEPSEEK_API_KEY 已配置
- ✅ CLOSEAI_API_KEY 已配置(用于GPT-5和Claude-4.5)
- ✅ JWT_SECRET 已修改为强密码
- ✅ CORS_ORIGIN 已设置正确的前端地址
- ✅ .env 文件已添加到 .gitignore
- ✅ 所有敏感信息未提交到Git
参考文档:
- 01-环境配置指南.md - 详细的配置说明
- 数据库连接配置 - 数据库专项配置