Nonlinear Performance Magnification

    flight-path
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.11 • Public • Published

    FlightPath

    Express style router for Fastly Compute@Edge

    Check the examples directory for examples

    This project is designed to offer an express style router for Fastly's C@E platform

    Usage

    Check out the docs

    Create a router object with const router = new Router();, this is the main object of FlightPath which all routes and middleware will be added to.

    Once all routes and middleware are added, you need to call router.listen(); to bind the router to the fetch event which is called on each request.

    A basic app would look like this:

    const router = new Router();
    
    router.get("/", async (req, res) => {
      return res.send("Hello World!");
    });
    
    router.listen();

    Methods

    The router object has functions for each HTTP method such as router.get and router.post which can be called with a path and a callback:

    router.get("/", async (req, res) => {
      return res.send("Hello World!");
    });

    There is also a router.route function which works the same as the specific method functions but allows you to pass the method as a string:

    router.route("GET", "/", (req, res) => {
      return res.send("Home");
    });

    If you wanted to bind to all methods you can use router.route and pass an * as the method to bind to all methods:

    router.route("*", "/", (req, res) => {
      return res.send("All methods!");
    });

    Paths and Parameters

    The path passed into a route can be either a pathname as specified in the URL specification or a path with parameter matching such as this:

    // Capture the word after /greeting/ as a variable called name
    // Reply to the path "/greeting/world" with "Hello world!"
    router.get("/greeting/:name", async (req, res) => {
      return res.send(`Hello ${req.params.name}!`);
    });

    Paths may also contain * to include anything such as this:

    // Return this message for any path starting with `/assets/`
    router.get("/assets/*", async (req, res) => {
      return res.send("This is where the assets would be!");
    });

    Install

    npm i flight-path

    DownloadsWeekly Downloads

    19

    Version

    1.0.11

    License

    ISC

    Unpacked Size

    911 kB

    Total Files

    68

    Last publish

    Collaborators

    • willoverton