Wrangler deploy to multiple zones same worker

When using wrangler, how to deploy the same worker/script to multiple zones (same or different route) without having to create a new worker with a unique name.

From the web interface, Is possible, I can add the route and point it to the same worker, and then in the " workers" page I see something like:

Deployed to:
example.foo.workers.dev, *.otherdomain.com/, *anotherone.com/

Any idea about how to achieve the same but from the command line using wrangler?

The way I do it is choosing one zone like example.com and setup wrangler for that zone.

wrangler publish

Then go on to the :logo: Dashboard, each zone, and manually set up a route to that script, in my case is relatively simple.

example.fr
example.de
example.co.uk

That’s indeed how I am also currently doing it but would prefer to do it from wrangler.

The main reason for this is that I would like to use the definitions in wrangler.toml as the source of truth for my routes and prevent going to the Dashboard every time I deploy something.

You could do a multi-script strategy with environments.

# top level configuration
type = "webpack"
name = "my-worker-dev"
account_id = "12345678901234567890"
zone_id = "09876543210987654321"
route = "dev.example.com/*"

# environment configuration
[env.staging]
name = "my-worker-staging"
route = "staging.example.com/*"

# environment configuration
[env.production]
name = "my-worker"
route = "example.com/*"

That will create 3 workers:

  • my-worker-dev
  • my-worker-staging
  • my-worker

And I want to have only 1 worker on multiple zones so that I could share it with all the zones, I tried using multiple routes something like:

routes = ['*example.com/', '*ejemplo.org/']

but I couldn’t find a way to do it when using multiple zones using wrangler (it works from the dashboard as explained previously)

I believe that https://github.com/cloudflare/wrangler/issues/866 is tracking this feature request.

I believe that https://github.com/cloudflare/wrangler/issues/866 is tracking this feature request.

I think the issue you posted is for multiple routes, not multiple zones, which is what the OP is asking.

I’m also looking for a way to do this in wrangler.

1 Like