zhizhi/backend-integration
copilot-swe-agent[bot] ebefa1f1da fix: address code review feedback — schema, comment, key collision, streaming fallback
Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
2026-03-10 10:02:39 +00:00
..
README.md feat: add backend API proxy layer for China network access 2026-03-07 07:31:58 +00:00
api-proxy.js fix: address code review feedback — schema, comment, key collision, streaming fallback 2026-03-10 10:02:39 +00:00
nginx-api-proxy.conf fix: address code review — CORS, input validation, timeout alignment, logging 2026-03-07 07:34:59 +00:00

README.md

后端集成中间层

  • 负责人:页页
  • 状态:进行中
  • 技术栈Node.js
  • 依赖模块:所有前端模块

API 代理层api-proxy.js

解决国内开发者无法直连海外模型 API + 前端 Key 暴露问题。

快速启动

# 1. 配置 API 密钥(推荐先用 DeepSeek国内直连
export DEEPSEEK_API_KEY=sk-xxx

# 2. 启动代理
node backend-integration/api-proxy.js
# 或用 PM2
pm2 start backend-integration/api-proxy.js --name api-proxy

# 3. 测试
curl http://localhost:3721/api/health
curl http://localhost:3721/api/models

接口

方法 路径 说明
POST /api/chat 聊天代理SSE 流式透传)
GET /api/models 列出已配置的可用模型
GET /api/health 健康检查

环境变量

变量 说明
DEEPSEEK_API_KEY DeepSeek 密钥(国内直连,推荐首选)
MOONSHOT_API_KEY Moonshot/Kimi 密钥(国内直连)
ZHIPU_API_KEY 智谱 AI 密钥(国内直连)
YUNWU_API_KEY 云雾 AI 密钥(团队推荐)
OPENAI_API_KEY OpenAI 密钥(需海外服务器)
GEMINI_API_KEY Google Gemini 密钥(需海外服务器)
PROXY_PORT 端口(默认 3721
RATE_LIMIT_RPM 频率限制(默认 10 次/分钟)

Nginx 配置

参见 nginx-api-proxy.conf,将 /api/* 请求代理到 Node.js 服务。

前端对接

前端铸渊聊天室docs/index.html已内置「后端代理模式」

  • 在设置页面选择「🔌 后端代理」提供商
  • 自动调用 /api/chat,无需用户填写 API Key
  • Key 由后端环境变量管理,不暴露给前端