From 3f11b13d5c300a86e45fb66a5084c25b52eff581 Mon Sep 17 00:00:00 2001 From: 18631081161 <2088094923@qq.com> Date: Wed, 21 Jan 2026 23:06:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniapp/config/index.js | 9 +++++++-- miniapp/utils/signalr.js | 10 ++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/miniapp/config/index.js b/miniapp/config/index.js index 1887089..6bdbd8d 100644 --- a/miniapp/config/index.js +++ b/miniapp/config/index.js @@ -10,13 +10,15 @@ const ENV = { development: { API_BASE_URL: 'http://localhost:5000/api/app', STATIC_BASE_URL: 'http://localhost:5000', - ADMIN_API_BASE_URL: 'http://localhost:5001/api' + ADMIN_API_BASE_URL: 'http://localhost:5001/api', + SIGNALR_URL: 'ws://localhost:5000/hubs/chat' }, // 生产环境 - 部署时修改这里的地址 production: { API_BASE_URL: 'https://app.zpc-xy.com/xyqj/api/api/app', STATIC_BASE_URL: 'https://app.zpc-xy.com', - ADMIN_API_BASE_URL: 'https://app.zpc-xy.com/xyqj/admin/' + ADMIN_API_BASE_URL: 'https://app.zpc-xy.com/xyqj/admin/', + SIGNALR_URL: 'wss://app.zpc-xy.com/xyqj/api/hubs/chat' } } @@ -34,6 +36,9 @@ export const config = { // 管理后台 API 地址 ADMIN_API_BASE_URL: ENV[CURRENT_ENV].ADMIN_API_BASE_URL, + // SignalR Hub 地址 + SIGNALR_URL: ENV[CURRENT_ENV].SIGNALR_URL, + // 请求超时时间(毫秒) REQUEST_TIMEOUT: 30000, diff --git a/miniapp/utils/signalr.js b/miniapp/utils/signalr.js index 8d9a702..9710de2 100644 --- a/miniapp/utils/signalr.js +++ b/miniapp/utils/signalr.js @@ -53,14 +53,8 @@ class SignalRClient { return new Promise((resolve, reject) => { try { - // 构建 WebSocket URL - // API_BASE_URL: http://localhost:5000/api/app 或 https://xxx.com/api/app - // Hub URL: ws://localhost:5000/hubs/chat 或 wss://xxx.com/hubs/chat - let baseUrl = config.API_BASE_URL - // 移除 /api/app 后缀,获取服务器根地址 - const serverUrl = baseUrl.replace(/\/api\/app$/, '') - // 将 http/https 替换为 ws/wss - const wsUrl = serverUrl.replace(/^http/, 'ws') + '/hubs/chat' + // 使用配置中的 SignalR URL + const wsUrl = config.SIGNALR_URL console.log('[SignalR] 正在连接:', wsUrl)