Skip to content

refactor(web): split index.html into html/css/js with static asset routes - #56

Merged
IRmsk merged 1 commit into
IRmsk:mainfrom
AptS-1547:refactor/web-console-split
Nov 26, 2026
Merged

IRmsk merged 1 commit into
IRmsk:mainfrom
AptS-1547:refactor/web-console-split

Conversation

@AptS-1547

Copy link
Copy Markdown
Contributor

Closes #54 (delivers Option B — static asset routes, per the issue's recommendation)

What

src/web/index.html was a single 2973-line / 132 KB file mixing HTML, CSS, and JS. This PR splits it by language and serves the parts through local static routes instead of re-inlining them:

  • index.html keeps only the skeleton (250 lines): <link href="/console.css"> plus six <script src="/js/*.js"> tags in the original section order
  • New files: console.css and js/{core,generate,map,draw,records,boot}.js — cut strictly along the file's own existing section markers, zero logic changes
  • web/mod.rs: STATIC_ASSETS table (path, content, content-type) as the single asset list; respond_html generalized to respond_static; static routes are GET-only, public like /, and keep the same no-store cache semantics
  • New test skeleton_asset_references_and_routes_agree pins the wiring both ways (skeleton references ↔ route table): a missing route or a dead route both turn red

Why this is behavior-preserving

  • The split is a pure line-range cut: reassembling the parts and comparing against the original file passed a byte-for-byte cmp (before adding the one-line source comments)
  • Classic <script src> tags execute in document order and share the global lexical scope — semantically identical to the previous single inline <script>; top-level const/let visibility and the core.js → … → boot.js reference order are unchanged
  • Served bytes equal source bytes (verified below), and the page already loaded Leaflet from unpkg the same way; respond_html sets no CSP

Verification

  • cargo fmt --check / cargo clippy --all-targets: clean
  • cargo test: full suite green (27 web-module tests, incl. the new wiring test); the one pre-existing failure api::accounts::tests::key_sources_fall_back_past_the_posix_defaults also fails on a clean checkout on macOS and is unrelated
  • node --check on each split js file: syntax-valid standalone
  • Live smoke test against pace-forge web: / → 200 text/html with all 7 references; all 7 assets → 200 with correct content types and no-store; each served response byte-identical to its source file (cmp); unknown asset path → 404; POST /js/core.js → 404 (static interception is GET-only)

…utes

web/index.html 单文件 2973 行 / 132 KB,三种语言挤在一起:编辑器支持
失效、diff 噪音大、JS 内部早已有清晰分节注释却没有文件边界。

拆分与下发(上游 issue IRmsk#54 的方案 B):
- index.html 保留骨架(250 行),<link href="/console.css"> +
  6 个按原分节顺序排列的 <script src="/js/*.js">
- console.css + js/{core,generate,map,draw,records,boot}.js 经
  web/mod.rs 的 STATIC_ASSETS 静态路由下发,与外链 unpkg 的 Leaflet
  同一加载模式;respond_html 合并为 respond_static(带 Content-Type)
- 静态路由只拦 GET,与首页同级公开(内容此前就随 / 公开),沿用
  no-store 缓存语义

行为等价性:
- 拆分是纯按行切割:拼接结果与原文件 cmp 字节级一致
- 经典 script 按文档顺序执行且共享全局词法作用域,与原单 <script>
  内联语义等价,JS 逻辑零改动(仅各文件头一行来源注释)
- 新测试 skeleton_asset_references_and_routes_agree 双向钉住骨架
  引用与路由表(忘接线/死路由都红);其余前端断言按文件归属分流

验证:cargo fmt/clippy 干净,web 27 项 + 全量测试通过;起服冒烟,
7 个静态资源响应与源文件逐字节一致,未知路径与 POST 落 404。

References IRmsk#54(IRmsk/pace-forge)。
@AptS-1547
AptS-1547 force-pushed the refactor/web-console-split branch from 4206738 to 9bfc8ec Compare November 26, 2026 16:10
@IRmsk
IRmsk merged commit 656e84f into IRmsk:main Nov 26, 2026
@AptS-1547
AptS-1547 deleted the refactor/web-console-split branch November 26, 2026 16:16
@IRmsk

IRmsk commented Nov 26, 2026

Copy link
Copy Markdown
Owner

合了,谢谢。

我在本地把拆出来的文件拼回去和原文件比过,除了你加的几行来源注释,逐字节一致;起了个 pace-forge web 实测,7 个资源返回的内容和源文件一模一样,未知路径和 POST 都是 404。

你长期那条(要不要上 ES module)我记下了,等前端真长到需要的时候再说。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: split web console index.html into html/css/js files (static asset routes)

2 participants