refactor: 白板路由改 /wb 前缀,消除 HTML 与 REST 同路径冲突

问题:GET /whiteboard/{board_id} 同时被 REST(返回 JSON)与 main.py 的 HTML 页面
注册,FastAPI 按注册顺序匹配到 REST,导致浏览器访问拿到 JSON 而非前端页面。

改为按职责分命名空间,避免冲突:
- HTML 页面:/wb/{id}(main.py)、/wb-admin(main.py,Basic Auth)
- 公开 REST:GET /api/wb/{id}(前端 init 拉取初始笔画)
- WS:/ws/wb/{id}(实时同步 + 心跳)
- 管理 REST:GET /api/admin/wb、DELETE /api/admin/wb/{id}(Basic Auth)

前端 whiteboard.js / whiteboard_admin.js、测试脚本、README 路径同步更新。
旧 /whiteboard/* 路径不再注册(404)。
This commit is contained in:
zikai
2026-07-21 14:51:33 +00:00
parent 3284269399
commit 7188c62d3a
7 changed files with 44 additions and 41 deletions

View File

@@ -16,7 +16,7 @@ import json
import websockets
BASE_WS = "ws://127.0.0.1:6890/ws/whiteboard"
BASE_WS = "ws://127.0.0.1:6867/ws/wb"
BOARD = "e2etest"
@@ -80,7 +80,7 @@ async def main() -> None:
# 验证 stroke_count 累计(之前 1 笔 + 1 次清空 = 2
import urllib.request
with urllib.request.urlopen(f"http://127.0.0.1:6890/whiteboard/{BOARD}") as r:
with urllib.request.urlopen(f"http://127.0.0.1:6867/api/wb/{BOARD}") as r:
meta = json.load(r)
print("stroke_count after ops:", meta["stroke_count"])
assert meta["stroke_count"] == 2, "1 笔 + 1 清空 = 2 次修改"