Repository navigation
refactor(web-dev): move the dev proxy out of apps/web into its own package - #784
Merged
Merged
Conversation
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
force-pushed
the
refactor/web-dev-package
branch
from
December 5, 2026 07:54
5f378fd to
4ecc542
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ADR-0022 slice 19a: the dev proxy of
just webleavesapps/webandpackages/web-toolsfor 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/webmay 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 saysapps/web/dev/proxy-guard.tsand 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
packages/web-dev:package.json(kindtoolfornpm run boundaries),Cargo.toml(kindui, as the plan says, so the size and layering checks see it as a unit) and the one-linerust/lib.rsthe other web packages have.Cargo.lockgains the package.src/proxy-guard.tsandsrc/proxy-guard.test.ts: moved withgit mvfrompackages/web-tools/src, content unchanged.src/vite-proxy.ts: the Vite plugin that runs the guard for HTTP and WebSocket upgrades and theserver.proxyandpreview.proxytable, moved verbatim out ofapps/web/vite.config.tsand wrapped indevProxy(env), which returns the resolved target and token, the plugin and the table.vite.config.tscalls it and goes from 112 to 55 lines; themeldframe-webcrate goes from 5,836 to 5,779 lines.apps/web/tsconfig.json: onepathsentry so thatviteresolves for the type imports of a package outsideapps/web, asvitestalready does.text-rules-lib.mjs(isProductSource) leavespackages/web-dev/out as it leavespackages/web-tools/out (tooling, not view source); its test names the new path. A comment infrontends/rune/apps/web-rune/scripts/proxy.mjsand thejust webentry ofAGENTS.mdname the new path; descriptions ofweb-toolsno longer mention the proxy.packages/web-tools/src, notapps/web/dev; only the plugin and routes were inapps/web. (2)xtask/size-allow.tomlhas no crate entry (the crate ceiling is 50,000 andmeldframe-webis only in the note of crates above 2,500 lines), so there is no entry to lower; the saving is the 57 lines out ofapps/web. (3)boundaries-allow.jsonandfrozen-allow.jsonare unchanged: no view file moved and no import changed kind.Testing
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, andapplyAuth. 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 loadsdevProxy, 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 ownAuthorization; a foreign Host, Origin,Sec-Fetch-Siteor 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 ownallowedHostscheck is switched off in that test so that the guard is the thing asked.Authorizationwith 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).meldframe-serverin memory with a throwaway dev token in its environment only, andviteofapps/webwithMELDFRAME_WEB_TOKENandMELDFRAME_SERVERpointing at it./v1/healththrough 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 Hostevil.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 checkinapps/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.shandsh scripts/ci/selftest.sh: clean. Commit messages:scripts/ci/message-patterns.shprints nothing.configurePreviewServerinstalls the same plugin and has no test),vite --hoston a real second machine, a remote target withMELDFRAME_WEB_ALLOW_REMOTE=1through a running server (resolved and unit-tested only), IPv6 loopback through a running server,just webitself (its recipe is unchanged; I ranvitewith its environment by hand),cargo xtask build-matrix, the Rune CI job for the one comment changed infrontends/rune.cora review --base origin/develop --no-llmran 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.