diff --git a/README.md b/README.md index b4af46e..e4fbd24 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ BOSS_DATA_FILE=.boss-data/local-dev.json npm run dev 默认云端入口: ```bash -http://111.231.132.51:43210 +http://111.231.132.51/boss/ ``` 这就是你当前最短的“主账号对话入口”。 @@ -154,7 +154,7 @@ npm run worker -- \ 打开云端控制台: ```bash -http://111.231.132.51:43210 +http://111.231.132.51/boss/ ``` 这是最符合产品策略的入口,也是主控面。 @@ -163,9 +163,9 @@ http://111.231.132.51:43210 仓库里自带一个简单 CLI,可以直接发消息给 Boss: ```bash -BOSS_SERVER_URL=http://111.231.132.51:43210 ./scripts/boss_chat.sh create "Boss 主控对话" -BOSS_SERVER_URL=http://111.231.132.51:43210 ./scripts/boss_chat.sh send "先调研这个问题,不要急着改代码。" -BOSS_SERVER_URL=http://111.231.132.51:43210 ./scripts/boss_chat.sh status +BOSS_SERVER_URL=http://111.231.132.51/boss ./scripts/boss_chat.sh create "Boss 主控对话" +BOSS_SERVER_URL=http://111.231.132.51/boss ./scripts/boss_chat.sh send "先调研这个问题,不要急着改代码。" +BOSS_SERVER_URL=http://111.231.132.51/boss ./scripts/boss_chat.sh status ``` 这条 CLI 入口后面也很容易改造成 Telegram / Slack / 企业微信 webhook。 diff --git a/compose.cloud.yaml b/compose.cloud.yaml index 292f00e..0828f34 100644 --- a/compose.cloud.yaml +++ b/compose.cloud.yaml @@ -6,6 +6,7 @@ services: environment: PORT: 43210 BOSS_DATA_FILE: .boss-data/cloud-store.json + BOSS_BASE_PATH: /boss ports: - "43210:43210" volumes: diff --git a/public/app.js b/public/app.js index 920b5bb..27d9fc2 100644 --- a/public/app.js +++ b/public/app.js @@ -10,6 +10,24 @@ const state = { banner: null, }; +function normalizeBasePath(pathname) { + if (!pathname || pathname === "/") { + return ""; + } + + return pathname.endsWith("/") ? pathname.slice(0, -1) : pathname; +} + +const appBasePath = normalizeBasePath(new URL(".", import.meta.url).pathname); + +function resolveUrl(path) { + if (/^https?:\/\//.test(path)) { + return path; + } + + return `${appBasePath}${path}`; +} + const TASK_GROUPS = [ { title: "进行中", statuses: ["assigned", "running"] }, { title: "等待处理", statuses: ["planning", "queued"] }, @@ -90,7 +108,7 @@ function renderBanner() { } async function request(url, options = {}) { - const response = await fetch(url, { + const response = await fetch(resolveUrl(url), { headers: { "Content-Type": "application/json" }, ...options, }); @@ -791,7 +809,7 @@ elements.resetDemo.addEventListener("click", async () => { render(); }); -const stream = new EventSource("/api/events/stream"); +const stream = new EventSource(resolveUrl("/api/events/stream")); stream.onopen = () => { const wasReconnecting = state.connection === "reconnecting"; diff --git a/public/index.html b/public/index.html index 43073c7..f1b8aa4 100644 --- a/public/index.html +++ b/public/index.html @@ -4,8 +4,8 @@