How to run workers on any subdomain?
Hi there!
I have a worker that I'd like to deploy both dev and production versions of to a zone. For simplicities sake, let's say the zone is
example.com
.
For my production worker, I'd like the worker to listen to every request to any subdomain and path to example.com
. To do this, I've added the route */*
and this works great.
However, I'd like to try to scope this a little more so that I can add a dev version to this zone too.
What I'd ideally like is for my production worker to handler requests that look like this: *.example.com/*
. I'd then like my dev worker to handler requests that look like this: *.dev.example.com/*
.
Is this possible? Or should I just look into getting a different domain?
Thanks!3 Replies
You can use environments (https://developers.cloudflare.com/workers/platform/environments/) for this
Thanks @Cyb3r-Jok3 , I probably wasn't clear enough in my original post.
After adding the route, I end up with the following message:
For example, adding
*.dev.example.com
In fact, even just adding *.example.com
gives me this error.
Actually, I just answered my own question:
Adding the following AAAA record seems to have fixed the warning:
Sorry to bug you!Yeah DNS records are only created when using custom domains https://developers.cloudflare.com/workers/platform/triggers/custom-domains/. Routes allow you to run workers in front of origins where as custom domains are an origin
Custom Domains · Cloudflare Workers docs
Custom Domains allow you to connect your Worker to a hostname, without having to make changes to your DNS settings or perform any certificate …