Cloudflare Worker that fronts SGTM container origins and related platform endpoints by resolving an incoming host to an upstream base URL, proxying requests, and emitting access logs to Supabase for analytics/observability.
{hostname}
/k/...
/mark-session-detection
OPTIONS
204
handleMarkSessionDetection
/put
env.ROUTING_MAP
env.ROUTING_MAP.get(hostname)
ctx.waitUntil(logAccess(...))
SUPABASE_SERVICE_ROLE_KEY
SUPABASE_SERVICE_KEY
SUPABASE_URL
LOG_FN_URL
ROUTING_MAP
makeCorsHeaders
Origin
Access-Control-Allow-Headers
Access-Control-Request-Headers
4xx/5xx
console.error
x-qaxal-router-target
ctx.waitUntil(...)
Cloudflare Worker that fronts SGTM container origins and related platform endpoints by resolving an incoming host to an upstream base URL, proxying requests, and emitting access logs to Supabase for analytics/observability.
Role in the platform
{hostname}to an upstream SGTM origin (and optionally a preview UI origin) via KV./k/...) where the true upstream target is encoded in a query param./mark-session-detection) that proxies to a Supabase Edge Function.Request flow
OPTIONS->204)./mark-session-detection(POST) to a Supabase Edge Function viahandleMarkSessionDetection./put(POST) to write onboarding routing config into KV (env.ROUTING_MAP).env.ROUTING_MAP.get(hostname))./k/...proxy requests (when not preview UI) to rewrite the upstream target.ctx.waitUntil(logAccess(...))).Security & trust boundaries
SUPABASE_SERVICE_ROLE_KEYorSUPABASE_SERVICE_KEYSUPABASE_URLLOG_FN_URLROUTING_MAPCORS & browser behavior
OPTIONS) return204with CORS headers frommakeCorsHeaders.Originand allow credentials.Access-Control-Allow-HeadersmirrorsAccess-Control-Request-Headerswhen present.Error handling
4xx/5xxresponses for missing KV entry, invalid routing config, and bad KV writes.console.errorwithout failing the proxied request.Observability
x-qaxal-router-targetto upstream request headers and downstream response headers.ctx.waitUntil(...)for non-blocking logging.Notes
/k/...decoding is best-effort and falls back to original path/search when decoding fails.