New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flight-path

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flight-path

Express style router for Fastly Compute@Edge

  • 1.0.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
475
increased by0.42%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 20 Apr 2022

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