diff --git a/app/config/chat.ts b/app/config/chat.ts index ec78ff2..d21cb6e 100644 --- a/app/config/chat.ts +++ b/app/config/chat.ts @@ -28,19 +28,42 @@ const extractAppId = (appUrl: string): string => { return appUrl; }; -// 获取Remix API路由的基础URL(客户端调用服务端API routes) -// 注意:客户端不再直接调用Dify API,而是调用Remix的API routes -// 服务端的API routes会通过dify-client.server.ts代理到FastAPI,再到Dify +// 获取FastAPI后端的基础URL +// 客户端直接调用FastAPI后端,不再通过Remix API routes中转 const getApiBaseUrl = () => { - // 客户端使用相对路径调用Remix API routes - return '/api'; + // 在客户端,从 API_BASE_URL 配置获取后端地址 + if (typeof window !== 'undefined') { + // 客户端:需要从某处获取 baseUrl 配置 + // 方案1: 从环境变量 + // 方案2: 从 window 全局变量 + // 方案3: 硬编码端口映射 + + // 获取当前端口 + const port = window.location.port; + + // 端口到后端地址的映射(与 api-config.ts 保持一致) + const portToBackend: Record = { + '5173': 'http://172.16.0.55:8000', + '51703': 'http://172.16.0.55:8073', + '51704': 'http://10.79.97.17:8001', + '51705': 'http://10.79.97.17:8002', + '51706': 'http://10.79.97.17:8003', + '51707': 'http://10.79.97.17:8004', + '51708': 'http://10.79.97.17:8005', + }; + + return portToBackend[port] || 'http://172.16.0.55:8000'; + } + + // 服务端:不应该被调用 + return ''; }; // 聊天应用配置 export const CHAT_CONFIG = { - // API相关配置 - 调用Remix API routes(不再直接调用Dify) - // 客户端 → /api/* routes → dify-client.server.ts → FastAPI /dify → Dify - API_URL: getApiBaseUrl(), + // API相关配置 - 客户端直接调用FastAPI后端的/dify路由 + // 客户端 → FastAPI /dify/* → Dify + API_URL: `${getApiBaseUrl()}/dify`, // 应用ID - 用于localStorage key(固定值) APP_ID: 'docreview-chat',