@cordis-tavern/ct-frontend-static
v0.1.0-rc.1
Published
cordis-tavern 的前端静态插件:SPA fallback —— 未具名路由回主 index 并返回 200
Readme
@cordis-tavern/ct-frontend-static
cordis-tavern 的 SPA fallback 插件:host 精准/前缀都未命中的请求(未具名路由)回退到主页(index),HTTP 200。
行为
| 步骤 | 说明 |
| --- | --- |
| inject | ['webServer'] —— host 未就绪时本插件保持 PENDING |
| 申领 fallback | webServer.fallbackRegister(handler),全局唯一槽位,卸载时 disposer 释放 |
| 回退 | 不读任何文件。返回 200 + 回退壳,浏览器 location.replace(homepage) 落到已注册主页 |
| 页面切换 | index 只是 JS 启动器;由动态路由库在客户端解析路径并完成切换 |
不读
distIndex/ 不readFile。index 不是映射表,无需服务端读盘再吐 HTML。
配置
| 键 | 默认 | 说明 |
| --- | --- | --- |
| homepage | '/' | 回退目标;须与 host 上已注册的 exact 主页路由一致 |
未知键与非法值 → TypeError 并指名键名。
装载
- 包名写进环境级
ct.profile:ct plugin add -p <环境名> @cordis-tavern/ct-frontend-static - 包目录须落在
$CT_HOME/profile/<env>/node_modules/或$CT_HOME/node_modules/ ct.bundle.path→cordis.patch.yml,insert[].id: frontendStatic
开发
pnpm build # 根仓库:esbuild → ct-frontend-static/dist/index.js
pnpm typecheck
pnpm test # 对 dist/ 产物