Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/anderly/cloudflare-worker-routing

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/anderly/cloudflare-worker-routing

  • v0.0.0-20180830141606-86a19e40cb1a
  • Source
  • Go
  • Socket score

Version published
Created
Source

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);
router.post('/cloudflare', SampleController.store);
router.get('/cloudflare/:id', SampleController.show);
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=' + req.params.id);
});
  • src/index.js is your main CloudFlare Worker entrypoint. Update the routes in the file and point to your functions / controller.
  • src/sample-controller.js contains an example of a basic controller
  • src/router.js contains the basic router (feedback welcome)
  • src/helpers.js contains some simple response/redirect helper functions
  • src/http-method.js is just a simple enum for HTTP verbs.

Credits to Dave Willenberg 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 🚀 with npm run deploy

Try it live

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

License

MIT

FAQs

Package last updated on 30 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc