default: {
    fetch(request, env, ctx): Promise<Response>;
}

Main Worker fetch handler.

Type declaration

Remarks

Routing behavior:

  • OPTIONS is treated as a universal CORS preflight.
  • /mark-session-detection (POST) proxies to a Supabase Edge Function.
  • /put (POST) writes hostname routing configuration to KV for onboarding.
  • All other requests are proxied to an upstream base determined by KV config and request path.

Upstream selection:

  • Preview UI paths (/gtm/debug, /gtm/static, /gtm/preview) route to preview_origin_url when available.
  • All other paths route to origin_url.

Proxy rewriting:

  • For non-preview requests under /k/..., attempts to decode the p query param and rewrite the upstream URL.

Param: request

Incoming downstream request.

Param: env

Worker environment bindings.

Param: ctx

Cloudflare execution context for waitUntil.

Returns

Proxied response.

Throws

This handler does not explicitly throw; it returns Response objects for error conditions.