Extract preview URL handling into a core module#797
Merged
Conversation
|
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.
e83c11f to
29d612a
Compare
commit: |
Contributor
📦 Preview BuildVersion: Install the SDK preview:
|
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.
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-onlySandboxExtensionmodel. The Sandbox DO retains lifecycle ownership (startup, activity/in-flight accounting, fetch interception);PreviewServiceowns 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, andproxyToSandboxkeep 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.