fix(admin): 改密后管理面板永久「连接中断」+ 顶部版本号多一个 v

- /ws 身份在握手时确定,而 startRealtime() 全生命周期只建一次连接;改密会作废
  服务端全部会话,服务端以 1008 关闭该连接,前端对 1008 是永久停止重连
  (给真鉴权失败设计的)→ 重新登录后无人重启连接,界面一直显示「连接中断」,
  只有重开窗口才会用新会话重新握手。
  修:新增 restartRealtime(),登录成功与退出登录时各重启一次(同时修掉
  「访客浏览后登录,旧连接仍是 guest 身份」的问题);1008 语义保持不变。
- AdminLayout 顶部版本号模板写死 v 前缀,而 serverHealth 已是完整版本串
  (dev_0.1.0)→ 显示成 vdev_0.1.0。

新增 web/src/admin/tests/event-realtime.test.ts 锁该行为(临时置空 restartRealtime
会失败);为让 node --test 能加载真实 store,测试解析钩子补 @/ 别名。
This commit is contained in:
AskaEth committed 2026-09-09 23:19:23 +08:00
1 parent 27bddefaad
commit a5941be9c4
5 files changed
+125 -3

No files matched your search

+16 -2
View File
@@ -1,11 +1,25 @@
/**
* `node --test` 专用的解析钩子:把 TS 源码里的无扩展名相对导入补成 .ts。
* 只服务于测试,不参与 Vite 构建。
* `node --test` 专用的解析钩子:把 TS 源码里的无扩展名相对导入补成 .ts,
* 并把 Vite 的 `@/` 别名映射到 src/。只服务于测试,不参与 Vite 构建。
*/
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
const SRC = new URL('../../', import.meta.url)
function resolveAlias(specifier) {
if (!specifier.startsWith('@/')) return null
const base = new URL(specifier.slice(2), SRC)
for (const ext of ['.ts', '.mjs', '.js', '/index.ts']) {
const candidate = new URL(base.href + ext)
if (existsSync(fileURLToPath(candidate))) return candidate.href
}
return null
}
export async function resolve(specifier, context, next) {
const alias = resolveAlias(specifier)
if (alias !== null) return next(alias, context)
if (specifier.startsWith('.') && !/\.[cm]?[jt]s$/.test(specifier)) {
for (const ext of ['.ts', '.mjs', '.js']) {
const candidate = new URL(specifier + ext, context.parentURL)