Spot my wrangler.toml bug! 😁

I have a worker file that is doing what I want to do. My issue is with how to spec the wrangler.toml file. Having read the documentation, I thought that you could add different environments to your toml file, using like [env.staging] type syntax.

So I am supposed to have just two entries, production + staging. Here’s the contents of my wrangler.toml file:

# production
# wrangler deploy
name = "research"
main = "src/index.js"
compatibility_date = "2023-10-30"
workers_dev = false
route = { pattern = "*example.com/research/*", zone_name = "example.com" }

##########################################################################

# staging
# wrangler deploy -e staging
[env.staging]
name = "research-staging"
workers_dev = true

But when I wrangler deploy -e staging, it adds the *example.com/research/* route for some reason. Since that adds that route, then when I try to deploy to production wrangler deploy, it complains that that example.com route is already taken by the staging worker and fails to deploy. I have to manually delete that route first on the staging one before I can push to production.

So why is it adding that *example.com/research/* route when I deploy the [env.staging] version, since I haven’t defined that route for that env? My understanding from the docs is when you use workers_dev=true it automatically makes a worker route (which it is doing), it just should NOT be adding the other route!

Is this a Cloudflare bug?

When you create an environment it inherits the settings that you don’t override. You didn’t specify the route key under staging so it uses the one set above. Override it in the staging section and it should work.

[env.staging]
name = "research-staging"
workers_dev = true
routes = []
1 Like

Thanks, makes sense, I guess I had misunderstood how the environment parsing worked. :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.