Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 2.7 KB

middleware-plugin.md

File metadata and controls

59 lines (44 loc) · 2.7 KB

middleware-plugin

MiddlewareStack plugin API.

Example

class Greeter {
  middleware (config) {
    return async (ctx, next) => {
      ctx.response.body = `Hello Mr ${config.surname}`
      await next()
    }
  }

  optionDefinitions () {
    return [
      { name: 'surname', description: 'Your family name.' }
    ]
  }
}

export default Greeter

MiddlewarePlugin ⏏

Kind: Exported class

middlewarePlugin.description()

A description to show in the usage guide.

Kind: instance method of MiddlewarePlugin

middlewarePlugin.optionDefinitions() ⇒ OptionDefinition | Array.<OptionDefinition>

Return one or more OptionDefinition objects to collect command-line input.

Kind: instance method of MiddlewarePlugin

middlewarePlugin.middleware(config, lws) ⇒ function | Array.<function()>

Return one of more Koa middleware functions.

Kind: instance method of MiddlewarePlugin

Param Type Description
config object The active lws config object.
lws Lws The active lws instance. Typically, only required for access to lws.server.