Skip to content

Add routes option to cloudflare.Worker#6744

Open
Makisuo wants to merge 4 commits intoanomalyco:devfrom
Makisuo:add-cloudflare-worker-routes
Open

Add routes option to cloudflare.Worker#6744
Makisuo wants to merge 4 commits intoanomalyco:devfrom
Makisuo:add-cloudflare-worker-routes

Conversation

@Makisuo
Copy link
Copy Markdown
Contributor

@Makisuo Makisuo commented Apr 15, 2026

What this adds

A new routes field on sst.cloudflare.Worker that attaches the Worker to one or more Cloudflare route patterns as an alternative to a full custom domain.

new sst.cloudflare.Worker("Api", {
  handler: "src/worker.ts",
  routes: ["example.com/api/*"],
});

Each pattern becomes a cloudflare.WorkersRoute resource, with the zone looked up from the pattern's hostname via the existing ZoneLookup provider — same machinery domain: already uses.

Why

Today cloudflare.Worker only exposes domain: "...", which maps to WorkersCustomDomain — i.e. the Worker owns the whole hostname. That's the right answer when a Worker is the only thing serving a subdomain, but it's not the only shape CF supports.

Routes are the other half of the CF dashboard's "Domains & Routes" panel. They're pattern-based, so multiple Workers (or a Pages project) can share a hostname and unmatched paths fall through to the origin. Concrete cases I keep hitting:

  • One Worker fronting example.com/api/* while the rest of the site is served by Pages or an existing origin
  • Migrating off an old origin incrementally, pattern by pattern
  • Running several Workers on the same apex domain

Without a native option you end up reaching into @pulumi/cloudflare directly and hand-rolling WorkersRoute + ZoneLookup next to the SST component. That works but it's friction for something that's a one-liner in wrangler.

@vimtor vimtor self-assigned this Apr 15, 2026
@Makisuo Makisuo marked this pull request as draft April 15, 2026 11:33
@Makisuo Makisuo marked this pull request as ready for review April 15, 2026 11:33
Copy link
Copy Markdown
Collaborator

@vimtor vimtor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your contribution @Makisuo

i left a minor comment, everything else looks very promising

may i ask what's your specific use case behind this feature?

Comment thread platform/src/components/cloudflare/worker.ts Outdated
Co-authored-by: Victor Navarro <vn4varro@gmail.com>
Comment thread platform/src/components/cloudflare/worker.ts Outdated
@Makisuo
Copy link
Copy Markdown
Contributor Author

Makisuo commented Apr 15, 2026

I use Cloudflare Routes quite a lot for wildcard domains.
I know it's possible to just do this with ZoneRules instead, but then it won't be automatically linked and shown in Cloudflare making it harder for me and other team members to work with.

@Makisuo Makisuo requested a review from vimtor April 15, 2026 15:07
* Cloudflare zone on the same account. Wildcard hostnames like `*.example.com`
* are not supported here.
*
* A proxied DNS record for the hostname must already exist in the zone —
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as i'm learning more about this routes feature, i'm thinking whether it's a good idea to automatically create the DNS record for the user

if we don't, probably we should add an example of how to do it. ideally, we would create it, but i guess if you have multiple workers, that defeats the purpose

maybe you're more familiar and have a clear idea of how to deal with this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any ideas @Makisuo?

for the recent redirects features we are creating the record

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry completely missed the previous comments, Github Notifications are a bit broken for me currently.
Think it makes sense if we automatically create a DNS record if not already existing.

Have often seen people be confused why routes weren't working since this pattern isn't quite clear anyways, so this makes a lot of sense

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! if you add that, i will merge the pr

ideally, also attach some screenshots/video of it working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants