Repository navigation
VC1: the apps on Workers - #2
Merged
Merged
Conversation
The v0 SDK example's two apps, each its own Cloudflare Worker per environment through @opennextjs/cloudflare: apps/web (the host — the chat UI, its server routes and the preview iframe) and apps/preview (upstream's apps/preview-proxy, the preview proxy on an origin of its own, so generated code never runs on the host's). What Vercel supplied around them is replaced: - Related Projects told each app the other's URL. Each build is now told it instead: NEXT_PUBLIC_V0_PREVIEW_PROXY_URL and NEXT_PUBLIC_V0_CLONE_ORIGIN are inlined at build (the environment's override when set, else the sibling Worker's workers.dev URL — wired in VC3), and `next dev` still gets localhost:3000/3001 as upstream does. Origins are validated as before; plain HTTP is allowed on loopback only. - Vercel OIDC, the fallback credential, has no Cloudflare equivalent and is left out: the key is V0_API_KEY (optional), else the visitor's own, saved through the dialog into an HTTP-only cookie on each origin. - V0_API_BASE_URL (unset in a product) points the v0 calls at another origin with the same paths — the stand-in v0 API the e2e serves. Also: a health route per app for the deploy's smoke (it names the other app's origin, and whether a server key is set, never its value); pnpm 10 + Node 22 and the reference's lint; Next 16.2.4 → 16.3.8 (the reference's OpenNext-tested version); the cookie and storage keys no longer carry the example's name. Upstream's bun tests run under vitest in tests/web, with new tests in tests/web and tests/preview for the origins, health, the proxy's key route (CORS from the host only), trusted preview hosts, the same-origin seam and the v0 fetch override: 43 + 19 green. Both Workers fit Workers Free (web 2,173 KiB, preview 1,600 KiB gzipped). Under wrangler dev, against a stand-in v0 API: both serve with no key, the host's dialog validates a key, the proxy accepts it only from the host's origin, and a chat's preview is served through the proxy with v0's token. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn
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.
The v0 SDK example's two apps, each its own Cloudflare Worker per environment, built by
@opennextjs/cloudflare:apps/web: the host app, with the chat UI, its server routes and the preview iframe.apps/preview: upstream'sapps/preview-proxy, on an origin of its own, so generated code never runs on the host's origin.What replaces Vercel
NEXT_PUBLIC_V0_PREVIEW_PROXY_URLandNEXT_PUBLIC_V0_CLONE_ORIGINare inlined at build time. Each is the environment's override when set, else the sibling Worker's workers.dev URL (wired in VC3).next devkeepslocalhost:3000/3001, as upstream does.V0_API_KEY(optional), else the visitor's own, saved through the dialog into an HTTP-only cookie on each origin.V0_API_BASE_URL(unset in a product) points the v0 calls at another origin with the same paths. It exists for the stand-in v0 API in the e2e.Also in this PR
tests/web.tests/webandtests/previewcover the origins, the health routes, the proxy's key route (CORS from the host only), trusted preview hosts, the same-origin seam and the v0 fetch override.Checks run locally
pnpm typecheck,pnpm lintandpnpm testare green: 43 web tests and 19 preview tests.wrangler dev, against a stand-in v0 API:Generated by Claude Code