1.0.13 • Published 2 years ago

flight-path v1.0.13

Weekly downloads
3
License
ISC
Repository
github
Last release
2 years ago

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!");
});
1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.10

2 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago