Skip to content

Extract preview URL handling into a core module#797

Merged
ghostwriternr merged 2 commits into
nextfrom
preview-url-core-module
Jul 2, 2026
Merged

Extract preview URL handling into a core module#797
ghostwriternr merged 2 commits into
nextfrom
preview-url-core-module

Conversation

@ghostwriternr

@ghostwriternr ghostwriternr commented Jun 30, 2026

Copy link
Copy Markdown
Member

Move all preview URL functionality out of the Sandbox Durable Object into a dedicated module.

Preview URL handling had accumulated inside sandbox.ts: port exposure and token authorization, runtime activation checks, stale-runtime classification, proxy request construction, container TCP forwarding, and URL parsing/construction were all tangled into the DO facade. That made both sandbox.ts and the preview logic harder to read, test, and reason about in isolation.

This keeps preview URLs as core Sandbox functionality rather than an extension, because they touch Worker ingress, DO routing, fetch() interception, lifecycle hooks, container TCP forwarding, and DO storage — concerns that do not fit the RPC-only SandboxExtension model. The Sandbox DO retains lifecycle ownership (startup, activity/in-flight accounting, fetch interception); PreviewService owns the preview domain logic behind explicit dependencies, with focused helpers for proxy metadata, forwarding request construction, tokens, route parsing, and persisted state.

The change is behavior-preserving. The public API is unchanged: exposePort, unexposePort, getExposedPorts, isPortExposed, validatePortToken, and proxyToSandbox keep their existing contracts, and existing test suites continue to assert the same behavior. New unit tests cover route parsing/URL construction and the preview proxy protocol helpers.

@changeset-bot

changeset-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 29d612a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@aron-cf aron-cf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Move preview URL routing, state, and forwarding logic out of the
Sandbox Durable Object facade while keeping lifecycle ownership in the
core Sandbox class.
Move proxy metadata, forwarding request construction, and token helpers
behind focused preview utilities so PreviewService stays centered on
preview URL state and lifecycle decisions.
@ghostwriternr ghostwriternr force-pushed the preview-url-core-module branch from e83c11f to 29d612a Compare July 2, 2026 14:59
@ghostwriternr ghostwriternr enabled auto-merge (squash) July 2, 2026 14:59
@pkg-pr-new

pkg-pr-new Bot commented Jul 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/sandbox@797

commit: 29d612a

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📦 Preview Build

Version: 0.0.0-pr-797-29d612a0

Install the SDK preview:

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@797

🐳 Docker images were not rebuilt — no container changes detected. Use the latest release images from Docker Hub.

@ghostwriternr ghostwriternr disabled auto-merge July 2, 2026 15:07
@ghostwriternr ghostwriternr merged commit bc8bad7 into next Jul 2, 2026
15 of 17 checks passed
@ghostwriternr ghostwriternr deleted the preview-url-core-module branch July 2, 2026 15:07
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.

2 participants