❀Narrating Prophetic Monks
    Have ideas to improve npm?Join in the discussion! Β»

    @adonisjs/middleware-base

    1.0.0Β β€’Β PublicΒ β€’Β Published

    Adonis Middleware Base πŸ“

    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

    MiddlewareBase

    Functions

    registerGlobal(middleware) β‡’ void

    Register global middleware

    use(middleware) β‡’ void

    Register server type middleware

    registerNamed(middleware) β‡’ void

    Register an object of named middleware

    composeServer() β‡’ Runner

    Composes server level middleware

    composeGlobalAndNamed(namedReference) β‡’ Runner

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

    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

    Install

    npm i @adonisjs/middleware-base

    DownloadsWeekly Downloads

    7,652

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    15.4 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar
    • avatar