Skip to content

fix(server): harden embedded web UI serving#19314

Open
BYK wants to merge 1 commit intoanomalyco:devfrom
BYK:embed-web-ui-v2
Open

fix(server): harden embedded web UI serving#19314
BYK wants to merge 1 commit intoanomalyco:devfrom
BYK:embed-web-ui-v2

Conversation

@BYK
Copy link
Copy Markdown
Contributor

@BYK BYK commented Mar 26, 2026

Issue for this PR

Closes #19313

Builds on #19299 by @thdxr (now merged) and supersedes #15721.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Hardens the embedded web UI feature from #19299 with five improvements:

1. Font filtering (~27MB binary savings)
Only embeds core fonts (Inter + IBM Plex Mono). The 12+ optional monospace fonts are excluded and fall through to the CDN proxy at runtime. Users only ever use one monospace font.

2. Pre-bootstrap static middleware
Inserts a .use() middleware before Instance.provide() that serves exact static file matches. Without this, every asset request (CSS, JS, images, fonts) triggers Instance.provide()InstanceBootstrap → DB migration checks. This was a known production issue documented in AGENTS.md.

3. SPA fallback routing
Page routes (no file extension) now fall back to index.html for client-side routing. Asset requests (.js, .woff2, etc.) do not get the SPA fallback — they fall through to CDN proxy if not found locally.

4. OPENCODE_APP_DIR env var
Lets developers point at a local packages/app/dist without compiling a binary. Auto-detects the monorepo layout in dev mode.

5. CDN proxy fallback
Assets not found in the embedded bundle (e.g. excluded optional fonts) fall through to the existing CDN proxy instead of returning 404.

How did you verify your code works?

  • Binary builds successfully with font filtering (confirmed ~27MB reduction)
  • Asset requests bypass Instance.provide() (pre-bootstrap middleware)
  • SPA routes return index.html; asset 404s fall through to CDN
  • OPENCODE_APP_DIR=/path/to/dist serves local files correctly

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Build on anomalyco#19299 by @thdxr with several production hardening improvements:

- Filter optional fonts during embedding (~27MB savings) — only core fonts
  (Inter + IBM Plex Mono) are embedded, the rest fall through to CDN proxy
- Add pre-bootstrap static middleware before Instance.provide() to avoid
  DB migration checks on every asset request
- Add SPA fallback routing — return index.html for page routes but not for
  asset requests (which fall through to CDN proxy for excluded fonts)
- Add OPENCODE_APP_DIR env var for dev override
- Auto-detect packages/app/dist in monorepo dev mode
- Use explicit MIME type map instead of Bun.file().type for consistent typing
- CDN proxy fallback for any asset not found locally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden embedded web UI serving: font filtering, pre-bootstrap middleware, SPA fallback

1 participant