npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@adonisjs/middleware-base

v1.0.0

Published

Middleware base used by Http and Ws server

Downloads

17,813

Readme

Adonis Middleware Base :triangular_ruler:

This repo contains the code to make middleware work with the HTTP and Websocket server. If you are looking for generic middleware library, try co-compose.

NPM Version Build Status Appveyor Coveralls

Usage

const MiddlewareBase = require('@adonisjs/middleware-base')

const middleware = MiddlewareBase('handle')

// register global middleware
middleware.registerGlobal(['App/Middleware/BodyParser'])

await middleware
  .getGlobalAndNamed([])
  .params([ctx])
  .run()

Classes

Functions

MiddlewareBase

Kind: global class

new MiddlewareBase(middlewareFn, [warnFn])

MiddlewareBase class is a simple abstraction written to work just with AdonisJs middleware layer.

Adonis has global, named and server middleware with a slight difference in each. So this class understands all and offers a simple abstraction around them.

| Param | Type | Description | | --- | --- | --- | | middlewareFn | String | The function to be called on middleware class | | [warnFn] | function | |

registerGlobal(middleware) ⇒ void

Register global middleware

Kind: global function
Throws:

  • InvalidArgumentException If middleware is not an array

| Param | Type | | --- | --- | | middleware | Array |

Example

middleware.registerGlobal([
  'Adonis/Middleware/BodyParser',
  'Adonis/Middleware/Session'
])

use(middleware) ⇒ void

Register server type middleware

Kind: global function
Throws:

  • InvalidArgumentException If middleware is not an array

| Param | Type | | --- | --- | | middleware | Array |

Example

middleware.use(['Adonis/Middleware/Static'])

registerNamed(middleware) ⇒ void

Register an object of named middleware

Kind: global function
Throws:

  • InvalidArgumentException If middleware is not an object with key/value pair.

| Param | Type | | --- | --- | | middleware | Object |

Example

middleware.registerNamed({
  auth: 'Adonis/Middleware/Auth'
})

composeServer() ⇒ Runner

Composes server level middleware

Kind: global function

composeGlobalAndNamed(namedReference) ⇒ Runner

Composes global and named middleware together. Pass empty array when no named middleware are supposed to be executed.

Kind: global function

| Param | Type | | --- | --- | | namedReference | Array |