How to have multiple external custom hostnames within the same zone name for my different Workers?
I have generally speaking small clients, and (in the future) many of them. Because of that, I need to be able to have external domain names pointing to my few different workers (i.e. a client has a domain on Gandhi/OVH/etc and points it towards my app) without having to necessarily transfer the domain to Cloudflare.
After some help on https://discord.com/channels/595317990191398933/812577823599755274/1405542977069121728:
* created the fallback origin (proxy.reeple.studio)
* added the custom hostname from my client (thorgal.caracal.agency)
* added the CNAME record on my client’s domain, with the value of my proxy
* added a new worker route
proxy.reeple.studio/*
pointing to my specific worker app
Since I only have one entry now, it works but because everything pointing to proxy.reeple.studio
is routed to my worker. In the future, whenever I get a new client asking me to use their domain name, this won't work in itself.
And I can't afford to buy a new domain for each new client just to have a new zone name and thus having a new fallback origin.
Is there any solution to this? Thanks in advance for the help4 Replies
Wait, I might be over-engineering this for no reason – I can simply create a CNAME pointing to my worker URL and only do that? Regardless if the custom hostname is handled by Cloudflare or not?
At your workers.dev? Nah doesn't work, that's why you need Custom Hostnames/CF For SaaS
If your clients aren't using CF DNS, you should be able to just make routes based on their hostnames.
Otherwise, another approach which will work for all, is making a gateway worker/router which reads the url/hostname and then directs appropriately to the right Worker. Pro or higher have Snippets which don't have a per request charge which can work as well except no bindings (but you can test on Workers and move after)
And if the client uses CF, is the gateway worker as you mention the only solution as well?
If they use Cloudflare and they Proxy the CNAME, it goes off the CNAME Target. You could have them point to specific targets routing to specific Workers and go that way. Gets a bit confusing though with non-proxied/external not having the same behavior. Could go the other way and tell your customers to only use it unproxied if they're using CF, to avoid issues with their configuration as well