Skip to content

ScriptersCF/node-cloudflare-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cf-router

A simple module for easily processing incoming requests to Cloudflare Workers.


NPM Codacy Badge FOSSA Status

This module is super-easy to use, and it's plug-and-play. Literally. All you have to do to start is to tell the module when you want to process a request, and it will handle everything for you.

In order to tell the module when it should process a request (or more specifically ,telling the router):

const { Router } = require("cf-router");
const router = new Router();
const apiRouter = new Router();

// Connecting routers
router.use("/api", apiRouter);

// Setting up paths
router.get("/", (req, res) => res.text("Hello, world!"));
apiRouter.get("/", (req, res) => res.text("Welcome to the API!"));
apiRouter.get("/welcome/:name", (req, res) => res.text(`Welcome, ${req.params.name}`));

// Listening for requests
addEventListener("fetch", event => {
    event.respondWith(router.serve(event.request));
});

FOSSA Status

About

A simple, yet powerful Cloudflare Workers router.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors