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

@aldojs/middleware

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aldojs/middleware

Middleware disptacher and composer

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

A middleware dispatcher and composer for Node.js applications. It provides a clean way to register and invoke a chain of middleware functions.

Install

npm add @aldojs/middleware

Dispatcher

To create a new Dispatcher instance, you may use createDispatcher utility:

let { createDispatcher } = require('@aldojs/middleware')

let dispatcher = createDispatcher()

Registering middlewares can be done using Dispatcher::use method

dispatcher.use(function middleware () { return 123 })

To dispatch some input data to the middleware chain, and await the result, you may use the Dispatcher::dispatch method

let result = await dispatcher.dispatch({ input: 'foobar' })

Dispatcher::dispatch accepts any input, not only objects.

Middleware

Each middleware could return any output value including promises.

Whether a middleware runs before or after a downstream middlewares depends on the middleware itself. For example, the following middleware would perform some task before the others

dispatcher.use((input, next) => {
  // Perform task

  return next()
})

However, this middleware would perform its task after the input is handled by the following middlewares

dispatcher.use(async (input, next) => {
  let result = await next()

  // Perform the task

  return result
})

Compose

Composing multiple middleware to make a single handler is easy using the compose utility:

const { compose } = require('@aldojs/middleware')

let middleware = compose([
  someMiddleware,
  AnotherMiddleware,
  WhyNotAThirdMiddleware
])

Keywords

FAQs

Package last updated on 12 Feb 2019

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