79e0f542be
问题分析:
直接让客户端调用FastAPI后端会遇到:
1. CORS跨域限制
2. Cookie无法在跨域情况下传递
3. 安全性降低
正确架构(三层代理):
浏览器 → Remix /api/* → FastAPI /dify/* → Dify
流程说明:
1. 浏览器:fetch('/api/chat-messages', { credentials: 'include' })
- 相对路径,同域请求,无CORS问题
- Cookie自动携带
2. Remix API routes (app/routes/api.chat-messages.tsx)
- 从session获取JWT
- 调用 difyClient.createChatMessage(..., jwt)
3. dify-client.server.ts
- 使用 API_BASE_URL (根据端口配置)
- 调用 FastAPI: http://baseUrl/dify/chat-messages
- 携带JWT: Authorization: Bearer {jwt}
4. FastAPI /dify 路由
- 验证JWT,提取username
- 调用Dify: http://nas.7bm.co:12980/v1/chat-messages
baseUrl配置(服务端使用):
- 端口51703 → http://172.16.0.55:8073
- 端口51704 → http://10.79.97.17:8001
- ...
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>