Files
wxapp_escort/utils/config.js
T
lik 0eb8578a30 refactor: 环境开关与服务基址收敛到 utils/config.js
- 新增 utils/config.js:DEBUG 一处控制 health/user/ws 三个服务的本地与线上地址,
  顺带集中 appId、识别链路超时、WS 心跳与重连参数
- request.js / api.js / chatmsg.js 改为从 config 取值,删除各自硬编码的基址
- 修正本地调试时聊天 WS 仍连线上导致 token 查不到用户的问题
- PROJECT_GUIDE 同步接口与配置约定
2026-10-31 18:50:22 +08:00

34 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 全局配置:环境开关、服务基址与网络参数集中在这里,上线只需改 DEBUG,
// request.js / chatmsg.js / api.js 均从这里取值
// 本地调试开关:置 true 时直连本机进程(health :9004、user :9010、ws :9005)
// 线上由 nginx 按路径分流(/user → 9010、/health → 9004),两个服务共用同一域名
const DEBUG = true
const LOCAL_HOST = '127.0.0.1'
const ONLINE_HOST = 'api.huashengtec.com'
module.exports = {
DEBUG,
// 服务端 wxsignin / wxgetphonenumber 用 appId 查 conf.json 里对应的
// appid+secret 去换 openid 和手机号,缺了会直接回 400「缺少 appId」
APP_ID: 'wxapp-escort',
// health 服务(request.js 默认实例)
BASE_URL: DEBUG ? `http://${LOCAL_HOST}:9004` : `https://${ONLINE_HOST}`,
// user 服务是独立进程,必须单独派生实例(api.js),
// 否则本地调试时 user 接口会打到 health 端口上走不通
USER_BASE_URL: DEBUG ? `http://${LOCAL_HOST}:9010` : `https://${ONLINE_HOST}`,
// AI 聊天 WebSocket:与 HTTP 同一开关,否则本机签发的 token 线上服务端查不到用户
WS_BASE_URL: DEBUG ? `ws://${LOCAL_HOST}:9005` : `wss://${ONLINE_HOST}/health-ws`,
// 语音 / 图片识别链路最长可到 60s,单独放宽超时,避免网络稍慢就整单失败
AI_MEDIA_TIMEOUT: 90000,
// WebSocket 心跳与重连参数(chatmsg.js 的默认值)
WS_HEARTBEAT_INTERVAL: 30000,
WS_MAX_RECONNECT_ATTEMPTS: 3,
WS_RECONNECT_DELAY: 3000,
}