Simple Cloudflare Worker with built-in Routing

A simple Cloudflare Worker with built-in routing

Here’s a simple Cloudflare Worker with a built-in router that allows you to separate your worker logic into different functions and/or “controllers” so you can achieve a clean separation of concerns while working within the 1 script limit for non-Enterprise plans.

Sample route definitions:

router.get('/Cloudflare', SampleController.index);'/Cloudflare',;
router.put('/Cloudflare/:id', SampleController.update);
router.delete('/Cloudflare/:id', SampleController.destroy);
router.get('/Cloudflare/routes/:id', (req) => {
    return response('Response from closure instead of controller: id=' +;

See the GitHub repo here: GitHub - anderly/cloudflare-worker-routing: A simple Cloudflare Worker with built-in routing

Credits to @detroitenglish and his Password pwnage Cloudflare Worker for the auto-deploy script and webpack config.

Quick Start

  1. Rename example.Cloudflare.env to Cloudflare.env and edit the values as needed.
  2. Update the index.js file with your routes, use function closures or separate controller files and go to town with a simple Cloudflare Worker with built-in routing!
  3. Install deps with npm install
  4. Launch :rocket: with npm run deploy

Try it live

Try out the following routes from the sample repo live here:


This is an awesome boilerplate, thanks a lot for sharing!

1 Like

Thanks! Hope you find it useful!

1 Like