Stop overwriting existing routes with Worker Deploy with Wrangler

Hey guys, I'm trying to redeploy some workers but have noticed that the routes that have been added are getting wiped/overwritten with the routes in my wrangler.toml file. Is there anyway to stop this overwriting?
4 Replies
Chaika
Chaika•4mo ago
Hey 👋 You should treat your wrangler.toml as your source of truth/configuration data. You can use --keep-vars to stop deployments from removing enviroment variables you set in the dashboard, but that doesn't work for routes.
If you change your routes in the dashboard, Wrangler will override them in the next deploy with the routes you have set in your wrangler.toml. To manage routes via the Cloudflare dashboard only, remove any route and routes keys from your wrangler.toml file. Then add workers_dev = false to your wrangler.toml file. For more information, refer to Deprecations.
https://developers.cloudflare.com/workers/wrangler/configuration/#source-of-truth
dbwltkd
dbwltkd•4mo ago
Thanks for the response! Yeah I thought so... Do you know of any way to make deployments but to keep the routes persisting? I was thinking of using the --routes option in CLI deploy command but not sure how to set the zone_id for it. The last ditch effort is to set the routes via API after the deployment.
Chaika
Chaika•4mo ago
Well like it says, don't define them in your config/disable workers_dev and then you can freely set them in the dashboard/API without wrangler messing with them You're specifically telling wrangler "I want these to be my routes", so it's overriding all the others. All you have to do is stop defining them Adding them in the deploy command would result in the same issue of course your other option would be to put all your routes in your wrangler.toml and use it to manage them
dbwltkd
dbwltkd•4mo ago
Thank you for your help! I think the best way is to manage the routes via the API.