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

@aofl/middleware

Package Overview
Dependencies
Maintainers
2
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aofl/middleware

Simple base middleware class

  • 3.14.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
77
increased by250%
Maintainers
2
Weekly downloads
 
Created
Source

@aofl/middleware

Simple base middleware class.

Api Documentation

Installation

npm i -S @aofl/middleware

Methods

NameArgumentsDescription
constructor...[String]Define any number of middleware hooks. E.g. new Middleware('before', 'after', ...)
usecb[Function], hook[String]Register a middleware
iterateMiddlewarerequest[Object], hook[String], response[Object]Iterate middleware for a given hook

Example

const matchRoutes = (request, response, next) => {
  // match route logic based on request and response

  next(response, [err || null]); // next should be called to process the next middleware function in the queue. Otherwise, the operation stops.
};

class Router {
  constructor() {
    // other initialization logic
    this.middleware = new Middleware('before', 'after');
    this.before(matchRoutes); // register matchRoutes middleware
    this.after(updateView); // register updateView Middleware
  }

  before(fn) {
    this.middleware.use(fn, 'before');
  }

  after(fn) {
    this.middleware.use(fn, 'after');
  }

  async navigate(request) {
    const beforeResponse = await this.middleware.iterateMiddleware(request, 'before', Object.assign({}, request)); // middleware functions expect request, and optional response
    await this.middleware.iterateMiddleware(request, 'after', beforeResponse);
  }

  // ... other Router logic
}

Keywords

FAQs

Package last updated on 18 Mar 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