Confusion Regarding Environments for Workers
# workers-help
k
I have an existing worker already deployed on the default 'production' environment, I would like to create another 'dev' environment for development purpose and only deploy it to workers.dev. Yet, things didn't go quite expected. The new 'dev' worker was deployed with the command
wrangler publish --env dev
wrangler.toml:
Copy code
name = 'foo'
account_id = '<ACC ID>'
main = 'src/index.ts'
workers_dev = false
routes = ["foo.com/_api/*", "www.foo.com/_api/*"]
kv_namespaces = [{ binding = 'CONTENT', id = '<KV ID>', preview_id = '<KV ID>' }]
compatibility_date = '2023-05-16'
[env.dev]
workers_dev = true
kv_namespaces = [  { binding = 'CONTENT', id = '<KV ID>', preview_id = '<KV ID>' }]
Issues faced: - A new worker was created with the name 'foo-dev' (where foo is the original name of the 'production' worker), instead of adding a new environment to the existing foo worker - The ''foo-dev' was mapped to all 3 routes i.e. foo.com/_api/\*, www.foo.com/_api/* and foo-dev.foo.workers.dev Confusion: - I was once able to publish a worker with 2 different environments without having a new worker being created. Yet I can't find the same way to do so now. (Please see the screenshot. The 'contact' worker has another environment called dev). I tried the name the 'dev' worker with the same name 'foo' and the original one got overwritten. - As shown on https://developers.cloudflare.com/workers/platform/environments/#staging-environment-with-workersdev I can set
workers_dev
to true so it will only deploy to workers.dev. Yet, the all three routes are mapped to the new dev worker. I am aware that
routes
will be inherited so this might be an expected behaviour, but the documentation seem to be misleading (or maybe I got confused). May I know if there is a way to only deploy my worker to workers.dev for a specific environment. Thank you for your help!

https://cdn.discordapp.com/attachments/1108386385536229526/1108386386274430976/Screenshot_2023-05-17_at_21.22.27.png

i
Service Environments (the old method) had some issues and have been retired. The new "environments" do indeed create a new worker with the environment name appended.
k
I see. Thanks! Maybe the UI of the dashboard needs an update. Currently it always shows ‘1 environment’ which seems redundant as we always create a new one for each environment