Skip to content

refactor(web-dev): move the dev proxy out of apps/web into its own package - #784

Merged
ajianaz merged 2 commits into
developfrom
refactor/web-dev-package
Dec 5, 2026
Merged

ajianaz merged 2 commits into
developfrom
refactor/web-dev-package

Conversation

@ajianaz

@ajianaz ajianaz commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What

ADR-0022 slice 19a: the dev proxy of just web leaves apps/web and packages/web-tools for a package of its own, packages/web-dev. It is a pure move, with no change to what the proxy answers. The sign-in mode of slice 19b is written there afterwards. Refs the ADR-0022 Plan, slice 19a.

Why

Slice 19b changes the proxy (cookies pass through, no token, the Vite origin as the public origin). apps/web may only get smaller and the guard shared a package with unrelated tooling, so the code that 19b edits first moves to a package of its own, and gets the tests that say what it does today, before anyone edits it. The ADR text says apps/web/dev/proxy-guard.ts and a size entry to lower; neither is how the tree is (see Changes), so the move is what the code is, not what the plan names.

Changes

  • New package packages/web-dev: package.json (kind tool for npm run boundaries), Cargo.toml (kind ui, as the plan says, so the size and layering checks see it as a unit) and the one-line rust/lib.rs the other web packages have. Cargo.lock gains the package.
  • src/proxy-guard.ts and src/proxy-guard.test.ts: moved with git mv from packages/web-tools/src, content unchanged.
  • src/vite-proxy.ts: the Vite plugin that runs the guard for HTTP and WebSocket upgrades and the server.proxy and preview.proxy table, moved verbatim out of apps/web/vite.config.ts and wrapped in devProxy(env), which returns the resolved target and token, the plugin and the table. vite.config.ts calls it and goes from 112 to 55 lines; the meldframe-web crate goes from 5,836 to 5,779 lines.
  • apps/web/tsconfig.json: one paths entry so that vite resolves for the type imports of a package outside apps/web, as vitest already does.
  • text-rules-lib.mjs (isProductSource) leaves packages/web-dev/ out as it leaves packages/web-tools/ out (tooling, not view source); its test names the new path. A comment in frontends/rune/apps/web-rune/scripts/proxy.mjs and the just web entry of AGENTS.md name the new path; descriptions of web-tools no longer mention the proxy.
  • ADR-0022: a "Built, slice 19a" note under the plan entry, with where the plan's text differed from the tree and what 19b needs to know.
  • What differed from the plan: (1) the guard was in packages/web-tools/src, not apps/web/dev; only the plugin and routes were in apps/web. (2) xtask/size-allow.toml has no crate entry (the crate ceiling is 50,000 and meldframe-web is only in the note of crates above 2,500 lines), so there is no entry to lower; the saving is the 57 lines out of apps/web. (3) boundaries-allow.json and frozen-allow.json are unchanged: no view file moved and no import changed kind.

Testing

  • Test first: proxy-guard.refusals.test.ts (37 cases) was committed against the old location before the move and passed there: Host in malformed and look-alike forms, the port, Origin, WebSocket upgrade, the order of the checks, every method, content types and charsets, the PNG capture path, isProxied, the target and the opt-in, the token absent from every error and warning, and applyAuth. The 20 cases of the existing test are unchanged and pass in the new place.
  • vite-proxy.test.ts (14 cases) runs the real thing: a Vite dev server that loads devProxy, in front of a stand-in upstream. The token is added to REST, the capture upload and the WebSocket upgrade and replaces the browser's own Authorization; a foreign Host, Origin, Sec-Fetch-Site or content type is refused with nothing sent upstream; a refused upgrade never reaches the upstream; the token is in no answer and in no log line of the dev server. Vite's own allowedHosts check is switched off in that test so that the guard is the thing asked.
  • By-hand mutants (17): the Host, port, Sec-Fetch-Site and Origin checks, the upgrade rule, the JSON rule, the PNG path, the remote opt-in, the token check, the removal of a browser Authorization with no token, the guard on HTTP and on upgrades, hiding the url of a refused upgrade, the token on REST and on the socket, and the capture route and its guard. Each fails at least one test (dropping the Host check fails 12).
  • By hand against the real thing: meldframe-server in memory with a throwaway dev token in its environment only, and vite of apps/web with MELDFRAME_WEB_TOKEN and MELDFRAME_SERVER pointing at it. /v1/health through the proxy: 200. A read of a file through the proxy: 404 (the token was added; the same route direct with no token is 401). A JSON write through the proxy: 400 (authenticated, empty body refused). Foreign Host evil.example: 403 from Vite's own host check; foreign IP Host: 403 with the guard's words. Foreign Origin: 403. Sec-Fetch-Site: cross-site: 403. A text/plain write: 415. WebSocket upgrade with no Origin: socket closed with no answer. With the page's Origin: 101 from the server through the proxy. The token is in no output and in neither log.
  • npm run check in apps/web, run step by step: typecheck (0 errors), lint (every package, the new one included), boundaries (21 packages, 6 allowed, unchanged), frozen -- --base origin/develop (ok), test (131 files, 1,731 tests passed, 6 files skipped as before), build, ui-literals, licences: all pass. cargo xtask deps-check, size-check --base origin/develop, mm-check --base origin/develop, ui-literals, toolkit-swap --graph-only, sh scripts/ci/principal-mint.sh and sh scripts/ci/selftest.sh: clean. Commit messages: scripts/ci/message-patterns.sh prints nothing.
  • Not covered: the preview server (configurePreviewServer installs the same plugin and has no test), vite --host on a real second machine, a remote target with MELDFRAME_WEB_ALLOW_REMOTE=1 through a running server (resolved and unit-tested only), IPv6 loopback through a running server, just web itself (its recipe is unchanged; I ran vite with its environment by hand), cargo xtask build-matrix, the Rune CI job for the one comment changed in frontends/rune.
  • Cora (local): cora review --base origin/develop --no-llm ran the deterministic checks only and found no issues; no model-judged review ran here, so the verdict of the agent review is not claimed. The diff was read once more by its author, which is not an independent review.

The guard decides who may use the dev token (Host, Sec-Fetch-Site, Origin,
WebSocket upgrade, method and content type, the capture upload, the target
and the token). The cases state what it does today, so that the move to its
own package and the sign-in mode after it change no answer unseen.

Signed-off-by: Anaz S. Aji <12648688+ajianaz@users.noreply.github.com>
…ckage

ADR-0022 slice 19a. A pure move: the guard that decides which requests may
use the dev token (packages/web-tools/src/proxy-guard.ts and its tests) and
the Vite plugin and proxy table that applied it (apps/web/vite.config.ts)
now live in packages/web-dev, kind tool for the boundary check and kind ui
for the size and layering checks. vite.config.ts calls devProxy(env) and
shrinks by 57 lines, so the sign-in mode of slice 19b is written outside
apps/web.

The guard tests are unchanged. A test of the plugin against a real Vite
dev server and a stand-in upstream is added: the token reaches REST, the
capture upload and the WebSocket, and a foreign Host, Origin, fetch site or
content type is refused before the upstream sees it.

Signed-off-by: Anaz S. Aji <12648688+ajianaz@users.noreply.github.com>
@ajianaz
ajianaz force-pushed the refactor/web-dev-package branch from 5f378fd to 4ecc542 Compare December 5, 2026 07:54
@ajianaz
ajianaz merged commit 8791125 into develop Dec 5, 2026
11 checks passed
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.

1 participant