聊天接口

This commit is contained in:
18631081161 2026-01-21 23:06:32 +08:00
parent 447a4455dc
commit 3f11b13d5c
2 changed files with 9 additions and 10 deletions

View File

@ -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,

View File

@ -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)