Deploying a worker at multiple routes

Let’s say I have a zone example.com on Cloudflare with three domains, lorem, ipsum, and dolor. How do I deploy a worker to both lorem.example.com and ipsum.example.com (which can’t be matched by a single pattern other than *.example.com/*), but not dolor.example.com? (Using the pattern *.example.com/* will cause all matching domains, including dolor.example.com, to be routed to the worker.)

Apparently some users can do this in the Workers UI, but not me.

I’ve been looking for ways to deploy the same worker to multiple routes (in the sense of having more than one route patterns). How did you do this?

1 Like

You simply go into the UI and add more routes, selecting the same script as the one running.

2 Likes

Hmm… Could you be a bit more specific? I don’t see any option to add/remove routes in the Workers dashboard (https://dash.cloudflare.com/*/workers/overview) or the editor. What’s in your wrangler.toml file?

I have never used Wrangler to deploy multi-route scripts, I don’t know how multiple routes should be configured there. I guess you could easily configure them via the UI and then don’t overwrite them.

For the UI I should have been slightly more specific, you go into each zone’s Workers page, launching the editor there. You’ll see the routes tab.

That’s strange. I don’t see a “routes” tab on the editor page.

Because you not in the zone’s Workers tab. You are on the Workers overview editor.

Go into a zone/domain and select workers -> open editor.

You can do that with multiple routes.

Is this the page you’re talking about?

Yes. Open the editor.

1 Like

Oh jeez, missed it right in front of my face!

Thanks a lot!

2 Likes

Did you ever find a solution to deploying to multiple routes in toml file? I want to be able to deploy a worker to multiple routes in our CI pipeline, but currently this doesn’t look to be possible without having multiple toml files or possibly using environments, but they both feel like ugly solutions. Any help much appreciated.

1 Like

No, but then you don’t really have to. Just configure multiple routes for your Worker in the Dashboard, and choose a principal route to include in your wrangler.toml file. Existing routes won’t be affected when you publish an update, even though Wrangler would only show you the principal route.

Just to confirm, it’s not possible to put more than one route in wrangler.toml today. The team is aware of this limitation, and we’ll see what happens in the future!

1 Like

Another related question, is it possible to deploy to multiple routes using serverless framework, something like:

functions:
  myfunction:
    name: myfunction
    webpack: true #or the web pack config path for this function
    script: handlers/myfunctionhandler
    events:
      - http:
          url: example.com/myfunction
          method: GET
      - http:
          url: example.com/otherfunction
          method: GET

I have not personally used the serverless framework, so I don’t know. Maybe someone else does!

Not really sure about the exact structure, but if I remember correctly you can do exactly that. The structure seems correct, but don’t quote me on that.

If I’ll remember to check and I have the files somewhere I should have done it at least once…