Napoleon's Pixelated Mugshot
    Wondering what’s next for npm?Check out our public roadmap! »

    cloudflare-router
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.1 • Public • Published

    Cloudflare-Router

    A library for easily processing incoming requests to Cloudflare Workers. Created with TypeScript!


    NPM CircleCI codecov Codacy Badge FOSSA Status Dependencies 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("cloudflare-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 => {
        // Minimal boilerplate required
        event.respondWith(
            router.serve(event.request)
                .then(res => res.response)
        );
    });

    Installing

    Simply enter the following command into your terminal:

    npm install cloudflare-router
    

    FOSSA Status

    Install

    npm i cloudflare-router

    DownloadsWeekly Downloads

    9

    Version

    1.3.1

    License

    MIT

    Unpacked Size

    77.3 kB

    Total Files

    26

    Last publish

    Collaborators

    • avatar