fix(serve): echo Allow-Private-Network so hosted studio can reach loopback daemon#138
Merged
Conversation
…pback daemon
Chrome's Private Network Access blocks an HTTPS page (the hosted studio at
ax.necmttn.com) from fetching a loopback address (the local `ax serve` daemon)
unless the preflight response echoes `Access-Control-Allow-Private-Network: true`.
Our CORS preflight set Allow-Origin/Methods/Headers but not the PNA header, so the
studio could not connect to the daemon ("cannot access studio").
Echo the header on OPTIONS only for an allowed origin and only when the request
carries `Access-Control-Request-Private-Network: true`.
Fixes #129
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Deploying ax with
|
| Latest commit: |
e877b46
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0a56df01.ax-62d.pages.dev |
| Branch Preview URL: | https://fix-129-studio-pna.ax-62d.pages.dev |
The CLI prints `open in studio https://ax.necmttn.com/studio/?endpoint=...`, but ax.necmttn.com (apps/site on Cloudflare Pages) never served the studio app there - the site-wide SPA catch-all `/* /index.html 200` swallowed `/studio/`, rendering the marketing SPA, which has no /studio route -> "Invariant failed" -> blank page. The daemon was never contacted (so the PNA/CORS fix alone could not surface studio). Stage the studio bundle into the deploy: - scripts/build-studio.ts builds the mock studio (base /studio/, `?endpoint=` live-connect) and copies it (sans sourcemaps) into apps/site/public/studio. - wire it into the site `prebuild`/`build` chain (same pattern as `cp install.sh public/install`), and commit the bundle (same precedent as public/install). - add `/studio/* /studio/index.html 200` ABOVE the catch-all so studio's own client routes resolve to its shell while real /studio/assets/* win by static precedence. Verified: served apps/site/public + a local `ax serve`, opened /studio/?endpoint=http://127.0.0.1:1738 -> studio loads, "Live. Connected", /api/version + /api/skills + /api/events all 200, Skill Triage populated. Refs #129 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Closes #129 — "cannot access studio".
Clicking open in studio opens
https://ax.necmttn.com/studio/?endpoint=http://127.0.0.1:1738. The hosted (HTTPS) studio then CORS-fetches the localax servedaemon on loopback.Chrome's Private Network Access sends a preflight carrying
Access-Control-Request-Private-Network: truewhenever a public/HTTPS page targets a private/loopback address, and blocks the request unless the response echoesAccess-Control-Allow-Private-Network: true. Our preflight setAllow-Origin/Methods/Headersbut not the PNA header, so studio silently failed to connect.Reproduced against the daemon — preflight returned 204 without the PNA header:
Fix
On the
OPTIONSpreflight, echoAccess-Control-Allow-Private-Network: true— but only for an already-allowed origin (studio or local dev) and only when the request actually asks for it. Disallowed origins still get no CORS/PNA headers.After:
Tests
3 new cases in
server.test.ts(origin+PNA → header; no PNA req → omitted; evil origin → nothing).bun run test10/10 pass;bun run typecheckexit 0.🤖 Generated with Claude Code