Skip to content

deco-cx/cf-dispatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

cf-dispatch

Cloudflare Worker that routes incoming requests to deco storefront workers using Workers for Platforms dispatch namespaces.

How it works

This is the dispatch worker — a single Cloudflare Worker that sits in front of all deco storefront workers and routes requests to the correct one based on the hostname.

Routing

*-tanstack.deco.site subdomains:

  1. Extract subdomain from hostname (e.g., mysite-tanstack.deco.sitemysite-tanstack)
  2. Strip the -tanstack suffix → mysite
  3. Dispatch to the user worker named mysite in the namespace

Custom domains:

  1. Look up the hostname in the DOMAIN_MAP KV namespace
  2. Get the site name from the KV value
  3. Dispatch to the corresponding user worker

Isolation

This worker only handles requests matching the *-tanstack.deco.site/* route pattern. It does not interfere with other *.deco.site subdomains.

Bindings

Binding Type Description
DISPATCHER Dispatch Namespace The deco-storefronts namespace containing all user workers
DOMAIN_MAP KV Namespace Maps custom domain hostnames to site names

Configuration

See wrangler.jsonc for the full worker configuration. You'll need to replace placeholder values:

  • <kv-namespace-id> — Your KV namespace ID for domain mapping

Deployment

npx wrangler deploy

Architecture

Request → Cloudflare Edge
  → Route match: *-tanstack.deco.site/*
    → cf-dispatch worker
      → DISPATCHER.get(siteName)
        → User's storefront worker
          → Response

License

MIT

About

Dispatch worker that routes requests to deco storefronts on Cloudflare Workers for Platforms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors