{"id":13473996,"url":"https://github.com/anderly/cloudflare-worker-routing","last_synced_at":"2025-04-12T21:33:49.700Z","repository":{"id":140076595,"uuid":"144642283","full_name":"anderly/cloudflare-worker-routing","owner":"anderly","description":"A simple Cloudflare Worker with built-in routing","archived":false,"fork":false,"pushed_at":"2018-08-30T14:16:06.000Z","size":105,"stargazers_count":39,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T15:47:59.917Z","etag":null,"topics":["cloudflare","cloudflare-api","cloudflare-worker"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anderly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-13T22:59:52.000Z","updated_at":"2025-02-09T09:10:24.000Z","dependencies_parsed_at":"2024-01-02T23:04:44.559Z","dependency_job_id":"0af52e0b-24f7-4fcd-a919-695a1136afd7","html_url":"https://github.com/anderly/cloudflare-worker-routing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderly%2Fcloudflare-worker-routing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderly%2Fcloudflare-worker-routing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderly%2Fcloudflare-worker-routing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderly%2Fcloudflare-worker-routing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anderly","download_url":"https://codeload.github.com/anderly/cloudflare-worker-routing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248636199,"owners_count":21137397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-api","cloudflare-worker"],"created_at":"2024-07-31T16:01:08.667Z","updated_at":"2025-04-12T21:33:49.669Z","avatar_url":"https://github.com/anderly.png","language":"JavaScript","funding_links":[],"categories":["Workers"],"sub_categories":["Recipes"],"readme":"# A simple Cloudflare Worker with built-in routing\n\nHere'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.\n\nSample route definitions:\n\n    router.get('/cloudflare', SampleController.index);\n    router.post('/cloudflare', SampleController.store);\n    router.get('/cloudflare/:id', SampleController.show);\n    router.put('/cloudflare/:id', SampleController.update);\n    router.delete('/cloudflare/:id', SampleController.destroy);\n    router.get('/cloudflare/routes/:id', (req) =\u003e {\n        return response('Response from closure instead of controller: id=' + req.params.id);\n    });\n\n- [src/index.js](src/index.js) is your main CloudFlare Worker entrypoint. Update the routes in the file and point to your functions / controller.\n- [src/sample-controller.js](src/sample-controller.js) contains an example of a basic controller\n- [src/router.js](src/router.js) contains the basic router (feedback welcome)\n- [src/helpers.js](src/helpers.js) contains some simple response/redirect helper functions\n- [src/http-method.js](src/http-method.js) is just a simple enum for HTTP verbs.\n\nCredits to [Dave Willenberg](https://github.com/detroitenglish) and his [Password pwnage CloudFlare Worker](https://github.com/detroitenglish/pw-pwnage-cfworker) for the auto-deploy script and webpack config.\n\n---\n\n## Quick Start\n\n1. Rename `example.cloudflare.env` to `cloudflare.env` and edit the values as needed.\n2. 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!\n3. Install deps with `npm install`\n4. Launch 🚀 with `npm run deploy`\n\n## Try it live\nTry out the following routes from the sample repo live here:\n- GET https://anderly.com/cloudflare/\n- GET https://anderly.com/cloudflare/12345\n- GET https://anderly.com/cloudflare/routes/12345\n\n### License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderly%2Fcloudflare-worker-routing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanderly%2Fcloudflare-worker-routing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderly%2Fcloudflare-worker-routing/lists"}