Custom domain for cloudflare worker

Hi, this has probably come up before but a quick search doesn’t provide any clear answers:

Is there a way to use a custom domain (e.g. api.mydomain.com) with a cloudflare worker? I’ve tried just settings a cname to point to my worker but that never resolves.

Obviously without this feature workers would be entirely useless, so I think I’m missing something!

As a bit of further info, this is in support of an Open Data project (https://openchargemap.org) with the aim of load balancing a bunch of small read-only API clones. Currently our server gets pounded by lots of API users (who use it for free). I can stretch to the cost of unlimited workers ($5 per month) but that’s about it.

That subdomain will need a :orange: DNS entry. It doesn’t have to point to a real server if the Worker handles all requests. Something like 192.0.2.1 is a good place holder. And then you’ll be able to add that subdomain as a Route for that worker.

1 Like

Thanks! That’s awesome. I’d setup the worker under my main account and tried a cname but it didn’t work, then I followed your suggestion and it worked right away.

Looks like if you already have api.mydomain.com and your add a worker route api.mydomain.com it just takes over.

1 Like