Add routes option to cloudflare.Worker#6744
Conversation
Co-authored-by: Victor Navarro <vn4varro@gmail.com>
|
I use Cloudflare Routes quite a lot for wildcard domains. |
| * 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 — |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
any ideas @Makisuo?
for the recent redirects features we are creating the record
There was a problem hiding this comment.
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
There was a problem hiding this comment.
great! if you add that, i will merge the pr
ideally, also attach some screenshots/video of it working
What this adds
A new
routesfield onsst.cloudflare.Workerthat attaches the Worker to one or more Cloudflare route patterns as an alternative to a full custom domain.Each pattern becomes a
cloudflare.WorkersRouteresource, with the zone looked up from the pattern's hostname via the existingZoneLookupprovider — same machinerydomain:already uses.Why
Today
cloudflare.Workeronly exposesdomain: "...", which maps toWorkersCustomDomain— 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:
example.com/api/*while the rest of the site is served by Pages or an existing originWithout a native option you end up reaching into
@pulumi/cloudflaredirectly and hand-rollingWorkersRoute+ZoneLookupnext to the SST component. That works but it's friction for something that's a one-liner in wrangler.