Skip to content

Preview host: frames open on preview.openrepl.com/<token>/..., without /preview - #176

Merged
vickeykumar merged 3 commits into
masterfrom
feature/preview-host
Nov 23, 2026
Merged

vickeykumar merged 3 commits into
masterfrom
feature/preview-host

Conversation

@vickeykumar

Copy link
Copy Markdown
Owner

What

Optional Preview base URL (Site settings > Workspaces > Preview; a host name such as preview.openrepl.com, https assumed, no path). When set, the Preview frames, "open in a tab" and "copy address" use https://preview.openrepl.com/<token>/f/index.html and /<token>/p/<port>/... instead of https://openrepl.com/preview/<token>/.... Empty (default) keeps every address as it was. Built on the partial diff in preview_url_partail.diff (setting, validation, admin field, worker config).

How (minimal)

  • server/previewhost.go wrapPreviewHost, the outermost handler of the site, the gateway and a worker: on the preview host every path is turned into the site's own form (/preview/<token>/...) and marked; the same handlers serve it, so token validation, storage, libraries, programs and routing to workers are unchanged.
  • Only the preview is reachable on that host: every path ends below /preview/ (a non-token gives the "preview ended" 410), the root is 404. /preview/<token>/... is accepted on the host; the site's own /preview/... is unchanged.
  • The form follows the request: the prefix a program's links are rewritten to, the storage URL and the trailing-slash redirect use /<token>/... on the host (previewPath, publicPath).
  • Gateway -> worker: the mark travels as a trusted header (X-Openrepl-Preview-Host), stripped from clients, believed only over the tunnel; the setting reaches workers in WorkerConfig.
  • Page (27-preview.js): the tab history keeps the site's form; pub(), popUrl(), pathOf() make and read frame/tab addresses. settings.js carries the setting.
  • LLD 17, "The preview host".

To use

Point the host's DNS at the OpenREPL server, give it a certificate, and keep the Host header on the way (e.g. Cloudflare). If a CSP is set in front, it must allow the preview origin in a frame. Then enter preview.openrepl.com in the admin field and reload.

Tests

Go: the layer (both forms, the site untouched, /admin and root on the host), the file route on both hosts, the setting (bare host accepted, path/query/credentials refused), the mark to a worker (and a client's copy dropped), worker config. JS: preview-host.test.mjs. server, gateway, tunnel, trusted, livepreview Go tests and the page script tests pass. Not run: browser (e2e) specs and a real second hostname.

🤖 Generated with Claude Code

vickeykumar and others added 3 commits November 23, 2026 15:07
…hout /preview

SiteSettings.PreviewBaseURL (Site settings > Workspaces > Preview; a host name such as preview.openrepl.com, https assumed, no path; empty by default) moves the frames of the Preview to https://preview.openrepl.com/<token>/f/index.html and /<token>/p/<port>/... Empty keeps every address as it was.

A thin layer over the routes that exist (server/previewhost.go, the outermost handler of the site, the gateway and a worker): on the host every path is turned into the site's own form (/preview/<token>/...) and marked, then served by the same handlers, so the token, storage, libraries, programs and the routing to workers are unchanged. Nothing of the site is reachable there: every path ends below /preview/ (a non-token is 410), the root is 404. /preview/<token>/... stays valid on the site and on the host. The form follows the request: the prefix a program's links are rewritten to, the storage URL and the trailing-slash redirect use /<token>/... on the host. The gateway forwards the mark to a worker in a trusted header (stripped from clients, believed only over the tunnel); the setting reaches workers in WorkerConfig.

Page (27-preview.js): the history keeps the site's form; pub(), popUrl() and pathOf() make and read the addresses of frames, tabs and copy. LLD 17 'The preview host'.

Tests: the layer, both forms, the file route on both hosts, the setting, worker config, the mark to a worker, the page functions. Not run: browser specs, a real second host.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Preview base URL is kept as the admin typed it (no https:// added); the
scheme is derived where a full address is needed (http for a local host,
https otherwise). The host match and the check against OPENREPL_PUBLIC_URL
compare host names only, not scheme or port.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…; new tab uses the preview host

The setting is sent to the page and the workers as typed. The page adds the
scheme and port of the site it was opened from when none was typed. The
"Open in new tab" button now goes through popUrl like the pop-out window.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vickeykumar
vickeykumar merged commit fcc5ecb into master Nov 23, 2026
23 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