紧急修复:客户端改为调用Remix API routes,不再直接调用Dify API

根本问题:客户端代码直接调用Dify API(12980端口),绕过了服务端代理

修改内容:
1. app/config/api-config.ts
   - 添加独立的 difyBaseUrl 配置(指向外网 nas.7bm.co:8000)
   - 导出 DIFY_BASE_URL 供服务端使用

2. app/config/chat.ts
   - 移除直接Dify API配置(NEXT_PUBLIC_API_URL, APP_ID, API_KEY)
   - 移除 generateUserId 函数
   - API_URL 改为 '/api'(指向Remix API routes)

3. app/services/api.client.ts
   - 所有fetch调用改为相对路径 /api/*
   - 移除所有 Authorization 头(服务端自动处理JWT)
   - 移除所有 user 参数传递(服务端从JWT提取)
   - credentials 改为 'include' 以携带cookie

4. app/services/dify-client.server.ts
   - 使用 DIFY_BASE_URL 替代 API_BASE_URL

5. app/utils/dify-test.client.ts
   - 测试函数改为调用Remix API routes

调用链路:
客户端 → /api/* → Remix API routes → dify-client.server.ts → FastAPI /dify → Dify

解决问题:
-  不再直接调用 nas.7bm.co:12980(Dify端口)
-  统一通过 nas.7bm.co:8000/dify(FastAPI代理)
-  所有请求都经过JWT认证
-  user字段由后端自动管理

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-30 11:25:37 +08:00
parent 63acabccc9
commit cf6e9c2421
5 changed files with 62 additions and 122 deletions
+9 -1
View File
@@ -7,6 +7,8 @@
interface ApiConfig {
// 主API基础URL
baseUrl: string;
// Dify对话服务URL(独立配置,使用外网地址)
difyBaseUrl: string;
// 文档服务URL
documentUrl: string;
// 文档上传API URL
@@ -123,6 +125,7 @@ const configs: Record<string, ApiConfig> = {
// 开发环境
development: {
baseUrl: 'http://172.16.0.55:8000',
difyBaseUrl: 'http://nas.7bm.co:8000', // Dify对话服务使用外网地址
documentUrl: 'http://172.16.0.55:8000/docauditai/',
uploadUrl: 'http://172.16.0.55:8000/admin/documents',
oauth: {
@@ -137,6 +140,7 @@ const configs: Record<string, ApiConfig> = {
// 测试环境
testing: {
baseUrl: 'http://nas.7bm.co:8873',
difyBaseUrl: 'http://nas.7bm.co:8000', // Dify对话服务使用外网地址
documentUrl: 'http://nas.7bm.co:8873/docauditai/',
uploadUrl: 'http://nas.7bm.co:8873/admin/documents',
oauth: {
@@ -152,6 +156,8 @@ const configs: Record<string, ApiConfig> = {
production: {
// postgrest
baseUrl: 'http://10.79.97.17:8000',
// Dify对话服务使用外网地址
difyBaseUrl: 'http://nas.7bm.co:8000',
// minio
documentUrl: 'http://10.76.244.156:9000/docauditai/',
// 文件上传
@@ -171,6 +177,7 @@ const configs: Record<string, ApiConfig> = {
// 备用配置 (可以根据需要添加更多环境)
staging: {
baseUrl: 'http://172.16.0.119:9000/admin',
difyBaseUrl: 'http://nas.7bm.co:8000', // Dify对话服务使用外网地址
documentUrl: 'http://nas.7bm.co:9000/docauditai/',
uploadUrl: 'http://172.16.0.119:8000/admin/documents/upload',
oauth: {
@@ -344,7 +351,8 @@ export const apiConfig = getCurrentConfig();
// 导出具体的配置项,方便使用
export const {
baseUrl: API_BASE_URL,
documentUrl: DOCUMENT_URL,
difyBaseUrl: DIFY_BASE_URL,
documentUrl: DOCUMENT_URL,
uploadUrl: UPLOAD_URL,
oauth: OAUTH_CONFIG
} = apiConfig;