cf-worker-prune-routes

Prune unused cloudflare worker routes

Usage no npm install needed!

<script type="module">
  import cfWorkerPruneRoutes from 'https://cdn.skypack.dev/cf-worker-prune-routes';
</script>

README

Cloudflare Worker Prune Routes

When using routes in a cloudflare worker wrangler.toml file, changing a route does not delete the route from cloudflare, it only adds new routes. This can cause bugs if you aren't expecting it.

This script reads your wrangler.toml config, queries cloudflare for your existing routes, and removes any routes that aren't currently configured for your worker.

The intention is to run this after deploying route changes, to clean up any routes that may have been removed.

By default, this script will just output the routes that would have been deleted. If you want to actually delete the routes you must pass the --execute option

# in your cloudlfare worker repo
npx cf-worker-prune-routes --env staging
Options:
      --version  Show version number                                   [boolean]
  -c, --config   path to your wrangler.toml config
             [default: "./wrangler.toml"]
  -e, --env      The env for the worker routes you want to prune      [required]
  -p, --execute  Execute route pruning
  -v, --verbose  Show extra logs                                [default: false]
      --help     Show help                                             [boolean]