refactor: 环境开关与服务基址收敛到 utils/config.js
- 新增 utils/config.js:DEBUG 一处控制 health/user/ws 三个服务的本地与线上地址, 顺带集中 appId、识别链路超时、WS 心跳与重连参数 - request.js / api.js / chatmsg.js 改为从 config 取值,删除各自硬编码的基址 - 修正本地调试时聊天 WS 仍连线上导致 token 查不到用户的问题 - PROJECT_GUIDE 同步接口与配置约定
This commit is contained in:
+7
-5
@@ -1,14 +1,16 @@
|
||||
const WS_BASE_URL = 'wss://api.huashengtec.com/health-ws'
|
||||
// const WS_BASE_URL = 'ws://127.0.0.1:9005'
|
||||
// WS 基址与 HTTP 同源(config.DEBUG):本地调试时 HTTP 走本机,聊天也必须连本机,
|
||||
// 否则本机签发的 token 到线上服务端查不到用户,只会回「请先登录」
|
||||
const config = require('./config.js')
|
||||
const WS_BASE_URL = config.WS_BASE_URL
|
||||
|
||||
class AIChatSocket {
|
||||
constructor(url = `${WS_BASE_URL}/chat`, options = {}) {
|
||||
this.url = url
|
||||
this.options = {
|
||||
heartbeatInterval: 30000,
|
||||
heartbeatInterval: config.WS_HEARTBEAT_INTERVAL,
|
||||
autoReconnect: true,
|
||||
maxReconnectAttempts: 3,
|
||||
reconnectDelay: 3000,
|
||||
maxReconnectAttempts: config.WS_MAX_RECONNECT_ATTEMPTS,
|
||||
reconnectDelay: config.WS_RECONNECT_DELAY,
|
||||
...options
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user