Skip to main content
@tuturuuu/start-bridge is the shared layer that lets a satellite’s existing App Router source run under TanStack Start, Vite+ and Void on a Cloudflare Worker. It replaces the per-app src/runtime shim copies in Meet, Mail and Calendar. The core (route-match, base-path, mounts, app-url, endpoints, pages, api-forward, canary, csp, request-context/core) has no React, Start or Vite imports; the next/*, start/*, intl/* and vite entries are the framework adapters at the edge. This page is the v0 API freeze. App lanes convert against these export paths and signatures. Within v0, changes are additive only: a new optional option, a new export, or a new subpath. Removing or changing a frozen signature needs a new subpath and a coordinated migration.

Export map

Worker handler

Order: base resolution from mounts (a mount host outside the mount is 404), /assets/* and declared public files from ASSETS (base-stripped), then the app’s proxy.ts, centralFirst paths to the central API (Next beforeFiles rewrites such as TUTURUUU_WEB_WORKSPACE_API_RESERVED_PATHS; Next sources like /api/v1/:wsId/x or bracket patterns), the generated endpoint registry, unowned /api/* to the central API (base-stripped), server functions to Start (base-stripped), and finally pages to Start at the browser-visible URL. The response then gets Location rewriting. Cookies pass through unchanged. A proxy.ts rewrite to another origin throws unless that origin is the configured central API origin (rewriteOrigins), which is then fetched with manual redirects and hop-by-hop headers removed. In the app: start.ts passes serverFns: { fetch: bridgeServerFnFetch } to createStart, getRouter() sets basepath: routerBasepath() and ssr: { nonce: requestNonce() }, and the root route lists appBaseHeadScript() first in head().scripts. With csp set, every response gets a fresh nonce in its Content-Security-Policy, which the router and the head script repeat. On the apex the handler sits behind the one-origin gate (decideOneOriginRequest, #6746).

Registries and the unregistered-route check

Each app declares start-bridge.routes.json at its root:
bun packages/start-bridge/src/codegen/cli.ts generate apps/<app> writes the registries; check fails when appDir is missing or not a directory (declare "appDir": null for an app without App Router source), when a generated file is stale, a route.* or page.* is neither generated, owned by an existing native file, nor ignored with a reason, an owned/ignored entry names no file, two files map to one URL shape (including [id] vs [slug], or a page and a route), or a parallel/intercepting route appears. Route groups are dropped from patterns. The page manifest exports PagePattern; type the page model as satisfies Record<PagePattern, Loader> so a new page fails type-check until it is handled. *.bridge.gen.ts files are excluded from Oxc.

basePath contract

One compiled artifact serves an app at its subdomain root and mounted at tuturuuu.com/<app>. The Worker resolves the base per request from the host and path against mounts (rootHosts → ''; mountHosts + the /<app> prefix → /<app>; unlisted hosts default to the root, or 404 with unknownHost: 'reject'). The build-time TUTURUUU_BASE_PATH is only the fallback when no runtime base exists. Root mode is the identity everywhere. tuturuuu.com/meet is the Meet app root; product marketing moves to /products/<app>.

Internal API resolver registration

registerDefaultAppBaseResolver(resolver) is exported from @tuturuuu/internal-api/client and the package root. The callback receives a normalized path and returns a relative mounted path or an absolute URL. Clients, the shared singleton, resolveInternalApiUrl(path, baseUrl?), and app-origin helpers use this precedence for relative inputs: explicit per-call baseUrl > client options.baseUrl > per-client appBaseResolver > latest active registered default > built-in fallback. Explicit bases bypass both resolvers, including resolvers returning absolute SSR URLs. Absolute input URLs bypass all base resolution. With no registration, existing root and subdomain defaults remain. Register once in each app adapter entrypoint, before requests or hydration. Browser adapters can register appPath, or createApiPath(appApiPatterns, centralFirst) when they also call Web-owned routes. The resolver applies to all relative internal-api calls, so mixed consumers must select their app-owned routes rather than prefix every route indiscriminately. Server adapters must return an absolute URL using the incoming request host; a mounted relative path alone would still resolve against the configured Web origin. Read the bridge context inside the callback on every invocation:
This example addresses all calls to the incoming app host; adapters with central Web calls must apply their ownership policy in the callback. Never register a new resolver per request or close over one request’s URL or base. The portable internal-api module stores callbacks only; the bridge owns request isolation. The returned unregister function is idempotent, supports out-of-order cleanup, and restores the latest registration that is still active. Use it for adapter teardown or hot reload. Regression coverage: packages/internal-api/src/default-app-base-resolver.test.ts executes root, Meet and Mail mounts, SSR host selection, interleaved bridge requests sharing one client, per-client precedence, unregister, absolute bypass and prefix-once behavior. Consumer runtime acceptance remains with each app.

Shared session on the apex: decision (b), server-held session

Decision (user, 2026-10-26): every app mounted at tuturuuu.com/<app> shares one Tuturuuu session that page script cannot read. It is an HttpOnly, Secure, SameSite=Lax cookie served through a backend-for-frontend (BFF) session layer, with no JavaScript-readable access or refresh token anywhere. CSP and Trusted Types stay mandatory per app, but as defense in depth, not the gate. Apex cutovers stay held until the admission gate below reports ready. Subdomain hosts keep serving throughout. The product rules (logout scope, step-up, token lifetimes) are in Shared session.

Model

  • One writer. Web is the only component that creates, refreshes, rotates or clears the session cookie. Mounted Workers and satellites on the apex only read it: they validate the JWT and derive per-app claims in memory per request (as sessionMode: 'supabase-first' already does). They never write or clear sb-*, tuturuuu_app_session* or tuturuuu_web_app_session*.
  • No token in JavaScript. No access or refresh JWT is readable by page script, returned in a JSON body to a browser request, or kept in Web Storage, IndexedDB or the Cache API. The only exceptions are single-purpose capabilities that are topic- or object-scoped, last at most 5 minutes and cannot be exchanged for a session: realtime join tickets (60 s) and storage signed URLs.
  • Browser code reaches data only through same-origin /api/* (or the app’s own /<app>/api/*) with the cookie. Browser Supabase clients are retired.
  • Bearer clients are untouched. A request with Authorization: Bearer is authenticated by the bearer alone; its cookies are ignored and CSRF rules do not apply. Mobile and CLI keep their native flows.
  • Mounted mode comes from the URL. The bridge deletes any client-sent x-tuturuuu-app-base and sets its own from the resolved mount; auth code never trusts that header (#6774).
  • Stages. Stage A makes the existing sb-<ref>-auth-token* cookie HttpOnly and keeps Domain=.tuturuuu.com so subdomain servers keep reading it; ambiguous duplicate cookies are treated as unauthenticated for unsafe methods. Stage B moves to a host-only __Host- cookie after the first cutovers.
  • End state. The platform is moving to Cloudflare. The long-term session is a first-party signed HttpOnly cookie issued and verified in a Worker, with state in a Durable Object or D1. Supabase Auth becomes one identity provider behind an interface. Stage A and Stage B harden today’s cookie in the meantime; build no new features on the Supabase cookie format.

Mounted no-writer guard

The function-proxy change (#6774) covers server-function middleware only. The app’s ordinary proxy.ts and endpoint registry still reach the auth writers, for example /api/auth/verify-app-token and /api/auth/refresh-app-session, whose createPOST and createRefreshPOST (packages/auth/src/cross-app/server.ts) set Path=/ app-session cookies. Under (b) the guard is permanent:
  1. Bridge admission, before proxy.ts and endpoint dispatch: a mounted request (non-empty URL-derived appBase) to a session-minting endpoint gets a terminal 409 APP_SESSION_MOUNTED, with no verification, rotation or Set-Cookie. A same-origin mount needs no handshake, because the apex cookie is the session.
  2. The writers themselves: the app-session setters and clearAppSessionCookie refuse to write when the server-side bridge context is mounted (never a header). This also covers proxy.ts refresh and MFA redirects.
  3. Response backstop: mounted responses drop any Set-Cookie for app-session and Supabase session names, and drop Service-Worker-Allowed.
  4. Logout from a mounted app is a POST to Web /api/auth/logout.
  5. Expiry: a mounted Worker answers 401 SESSION_REFRESH_REQUIRED for API and server-function calls, and 303 to Web’s refresh endpoint for document navigations. It never refreshes itself.
Whole-handler tests run through createBridgeHandler:
  • mounted verify and refresh return 409 with no Set-Cookie;
  • mounted pages and APIs emit no session Set-Cookie, including on the MFA and refresh-failure paths;
  • root-mode controls behave exactly as today;
  • a client-sent x-tuturuuu-app-base never switches modes.

CSRF

Cookie-authenticated unsafe requests (no Authorization: Bearer) pass only with Sec-Fetch-Site: same-origin, or, when Fetch Metadata is absent, an Origin equal to the request’s own origin. same-site (sibling subdomains), cross-site, none, a missing or null Origin and any mismatch are rejected. The check is a framework-free helper applied by Web middleware, by bridge admission and by each BFF auth endpoint, with an explicit, tested exemption registry (provider webhooks, OAuth callbacks, bearer and native auth routes). It rolls out off, then report (at least 24 h clean in production), then enforce, with the mode injected by each adapter.

Admission gate

@tuturuuu/utils/one-origin-routing refuses the shared origin in every mode until a bffSessionReady input is true. That input requires CSRF enforce, the HttpOnly cookie, no browser Supabase client and the no-writer guard, read from runtime config. Each app still needs its own one-origin admission review (CSP, Trusted Types, content inventory).

Page adapter

The generic App Router page adapter (React Server Components) and the 'use server' path are owned by the conversion codemod in #6760, which also owns the RSC-environment shims for next-intl/* and next/root-params. The bridge keeps its request store on a global Symbol so every bundled environment observes the same request. The RSC next-intl hooks call use() on the request’s single cached config promise. That promise carries React’s status/value, and NextIntlClientProvider settles it before rendering children, so translated server components render inline. A hook that suspends makes Flight outline the component as a lazy row. React’s streaming renderer (19.2.8, and still 19.3.1) can leave a Suspense boundary unresolved when a boundary rendered after the shell has a fallback that suspends. The browser then reports React error #419. Keep Suspense fallbacks synchronous. A translated server component rendered above or beside the provider still suspends once; in development the bridge logs a one-time console.warn for it. Assert emitted HTML with findUnresolvedSuspenseBoundaries from @tuturuuu/start-bridge/start/suspense-boundaries; it must return []. It reports:
  • pending boundaries, under any identifierPrefix;
  • completions whose segment container (div, svg, math or table) is missing;
  • unfilled P: segments;
  • boundaries switched to client rendering ($RX, or <!--$!--> from the shell).
It reads the inline instruction scripts of stable React and the data-r*i templates of the external runtime.

Runtime tag

Cutovers are direct, with an instant one-step rollback prepared before the flip and a post-deploy watch (see the native Start migration runbook); there are no staged canaries. Tag every native response with x-tuturuuu-runtime: native (RUNTIME_HEADER; tagResponse with a native decision) so the watch can tell native traffic from the prior deployment. The cohort helpers in canary (decideCohort, TUTURUUU_NATIVE_CANARY_PERCENT) are retained but unused.

Vite preset

basePath defaults to TUTURUUU_BASE_PATH at build time. List shims explicitly when converting an app whose current config aliases only some next/* modules, so the bundle does not change. Worker SSR/RSC environments resolve workerd, worker, module and browser export conditions, matching Cloudflare’s runtime. A package whose browser entry needs a DOM therefore fails during server rendering, and its node entry is no substitute when it depends on jsdom. Do not reorder conditions per package; use a DOM-free implementation for code that renders on the server. For example, isomorphic-dompurify throws at import and dompurify has no sanitize without a window, so server-rendered rich text uses sanitize-html (Forms, Mail). Cover the swap with a @vitest-environment node test that mocks the DOM-only module to throw.

CI template

.github/workflows/native-start-app.yaml is the reusable validation for a bridged app. Each app keeps a thin caller (<app>-cloudflare.yaml) that owns the triggers, the path filters (the app, every workspace package in its dependency closure including packages/start-bridge/**, its artifact helper, bun.lock, the caller and the template), concurrency and the ci-check.yml gate, then calls the template with: Runtime setup uses .github/actions/install-native-runtime-prerequisites in both validation and restore acceptance. On the disposable Ubuntu runner it keeps Ubuntu’s suites, components and signing key, selects the official HTTPS archive instead of the Azure mirror, and sets three apt acquisition retries with 20-second HTTP/HTTPS inactivity timeouts. Index download failures are fatal. The existing ten-minute setup and four-minute runtime limits remain. Playwright still owns the complete Chromium/font dependency list and already uses --no-install-recommends; do not trim fonts to hide download failures. No package cache or whole-command replay is used. For a setup timeout, inspect the apt download host and timestamps separately from browser installation; then rerun the failed job after resolving transport failures. Regression coverage: node --test scripts/ci/native-runtime-prerequisites.test.js. The template validates the inputs and runs, on the exact source SHA: frozen install, dependency build, build identity, the registry check, unit tests, Oxc, the Void build, route-tree drift, type-check, emitted-config validation, emitted binding-type compatibility (a scoped harness: the generated bindings become a module importing only the Workers types they name, checked under the app’s own tsconfig, so global runtime types never retype app code), Wrangler deploy --dry-run, then seal → emitted runtime → verify → pack. A second job restores the archive into clean output and repeats the dry-run, runtime acceptance and byte verification. It has no publish job or provider credential; production stays held in tuturuuu.ci.ts. Apps with extra acceptance (Apps’ browser anchors, Meet’s realtime Worker) keep those steps in their own workflow until the template grows an input for them.

Verification

packages/start-bridge unit tests cover each core module and adapter at the root and under /meet, plus the ported Meet proxy-bridge regressions. App adoption still needs that app’s exact-commit CI: unit, type-check, lint, vp build, the sealed artifact and emitted-runtime acceptance where the app has them.