feat(chat): 页面级 basePath 引导(路径模式静态面)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-10-19 18:28:22 +08:00
parent 0baa9ab2ed
commit a1dc1ff7a3
3 changed files with 81 additions and 7 deletions
+6 -2
View File
@@ -1,8 +1,12 @@
// ---- basePath(spec 2026-10-19 §4):chat.html 引导脚本按 location.pathname ----
// ---- 推导并挂载 window.__BASE_PATH__(路径模式 /t/<slug>,Host 模式空串)。 ----
var B = window.__BASE_PATH__ || "";
// ---- Task 10: brand 拉取(同源 /api/public/brand,下方两个 IIFE 共用) ----
// 失败/超时(3s) → resolve(null) → 中性兜底,页面照常可用不白屏。
var chatBrandReady = (function () {
try {
var p = fetch("/api/public/brand", { cache: "no-store" }).then(function (r) {
var p = fetch(B + "/api/public/brand", { cache: "no-store" }).then(function (r) {
return r.ok ? r.json() : null;
}).catch(function () {
return null;
@@ -129,7 +133,7 @@ var chatBrandReady = (function () {
function getWsUrl() {
var loc = window.location;
var proto = loc.protocol === "https:" ? "wss:" : "ws:";
return proto + "//" + loc.host + "/ws/chat";
return proto + "//" + loc.host + B + "/ws/chat";
}
function connect(sessionKey) {