Question concerning mapping of CF Workers with single custom domain but different routes

Hi,

I’ve setup a worker and have followed some guides where I map a CNAME to the worker url.
So for instance:
custom_domain.com/api/v1/function → custom_function.workers.dev/api/v1/function

The DNS CNAME will be custom_domain.com ==> custom_function.workers.dev
And we can add the route custom_domain.com/api/v1/function into the worker configuration.

The above works.


But I’m trying to find instructions on how to set up additional workers that can be mapped to the same domain

So for instance

  1. custom_domain.com/api/v1/function1 → custom_function1.workers.dev/api/v1/function1
  2. custom_domain.com/api/v1/function2 → some_other_function.workers.dev/api/v1/function2

Now since the mapping is done with CNAME, it seems that CloudFlare does NOT support this kind of mapping.

Is my understanding correct?

I don’t even map routes to Worker URLs, nor are those valid CNAMEs. My “custom_domain” is a :orange: Proxied hostname. And since each Worker has a name, I’d map:

Those just happen to be a couple of workers I already have. I don’t know how a worker would have a full URL. Maybe I’m missing part of the picture.

@sdayman, thanks for the taking time to reply!

If I understand you correctly, I can map the custom domain to a proxied hostname and CF will take care of the rest?

No, this is Routing:

https://developers.cloudflare.com/workers/platform/routes

@sdayman, thanks for following up!

A follow up question is this: what is the DNS entry that is needed for my Domain (registered through CF) so that api.custom_domain.com will point to CF workers for it to resolve the routes?

I cant seem to find it in the docs.

Edit: I think I saw it. Is it this?

To support this, you should use the Cloudflare dashboard to add an `AAAA` record for `myname` to `example.com` , pointing to `100::`

So I should have an entry for AAA to point to “100::”

Edit2: It seems that I am missing something.

My DNS entry table only contains 1 record for the AAA entry presently.
But the root/naked domain does not have an entry. I am not sure what the entry should be.

@sdayman Thanks for the pointer that led me to read up more.
It seems like we need a “dummy” entry with type “A” record that points to nowhere before the mapping work.

So for the DNS entries (CF managed)

  1. Add a dummy A record, e.g. cferror → 192.168.0.1 (non-proxy)
  2. Add a AAA record, e.g. subdomain → 100:: (proxied)

This will allow CF managed DNS to resolve and offer the correct mapping to their infrastructure.

It is described in this post: Custom domain for workers?

You only need one dummy DNS entry. Either one will trigger the route. Personally, I use the “AAAA” record because it’s easier for me to remember the 100::

Oh thanks! I didn’t realise that.
When I tried only the AAA record, it didn’t work. But when I added the A record, it started working. Maybe it’s just a DNS propagation issue.

But thanks for the help! Great to have pointer to the right direction that helped me resolve this.

1 Like