How to properly set up a custom hostname with a worker?

I’m building a SaaS app with a Cloudflare Worker and would like my customers to be able to point their domains to the worker via a CNAME record. Steps taken so far:

  1. Launched a worker and assigned the worker.mydomain.com route to it on Cloudflare
  2. Added worker.mydomain.com as a fallback origin under SSL/TLS / Custom Hostnames on Cloudflare
  3. Added a worker AAAA 100:: proxied record under DNS on Cloudflare
  4. Added a custom hostname customerdomain.com via the API on Cloudflare. Both the SSL/TLS certificate status and the Hostname status are currently Active.
  5. Added a @ CNAME worker.mydomain.com record for customerdomain.com on a respective third-party domain service.

The request to customerdomain.com results in Error 522. However, the request to worker.mydomain.com results in the worker serving the expected content.

I have followed these guides:

https://developers.cloudflare.com/ssl/ssl-for-saas/getting-started#step-1--create-fallback-origin-and-cname-target
https://developers.cloudflare.com/ssl/ssl-for-saas/reference/worker-as-origin

Yet, to no avail. I’m in dire need of help.

2 Likes

Hello,
Can you please share here the syntax you used for the Worker route?
Did you use wildcards as mentioned in the documentation?

Hello,

I tried both worker.mydomain.com and *.mydomain.com/*. Neither of them worked. The dashboard won’t let me specify */* as the route and says that is is invalid and should contain mydomain.com

This indeed should work.
Could you please open a support ticket and let us know the ticket number here?
We’ll investigate further then.
Please provide all details in the ticket, with the real hostnames.

I have opened a support ticket #2311247, but it got closed automatically because I’m on a free tier, even though I subscribed to paid custom hostnames.

Please, reopen the ticket and investigate it or tell me if I need to subscribe to a Pro plan to be able to access support. However, paying $20 for the sole purpose of submitting a support ticket for something that does not work as described in the docs seems unfair.

Currently this issue is a blocker, as the rest of the MVP is ready to be deployed to production any time soon. At this point I’m either hoping to get this solved or will be forced to switch to AWS CloudFront or Fly.io. I, however, would rather prefer to stick with Cloudflare as I genuinely favour it over everyone else.

Hi @c2u5hed,

That’s not necessary. The community can escalate issues such as this to support, and Nic is already looking at this one for you.

Thank you, guys. I sincerely hope that you will help me resolve this.