Worker does not work with load balancing

For Workers & Pages, what is the name of the domain?

*mydomain.com

What is the issue or error you’re encountering

Worker returns 404 for root domain but works fine for subdomains

What are the steps to reproduce the issue?

Worker routed to *mydomain.com
When visiting “www.mydomain.com”, 404 error is returned.
When visiting “server1” and “server2” subdomain, worker returned successfully.

Since we have been using Cloudflare load balancer to distribute traffics among two web servers, I suspect that was the cause of this behaviour.

Is there a way to make it work?

How does your code look like to handle (sub)domain requests, or rather to route the requests to the load-balanced hostnames/origins? :thinking:

Does www DNS record exist alongside server1 and server2?

Might be the Worker doesn’t fetch the root domain while it does sub-domains, otherwise might have to use 2 worker routes, one for *.mydomain.com (sub-domains) while the other for mydomain.com (except if some redirect rule is interfering “in between”)? :thinking: