middleware-plugin.md
July 6, 2021 · View on GitHub
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
- middleware-plugin
- MiddlewarePlugin ⏏
- .description()
- .optionDefinitions() ⇒
OptionDefinition|Array.<OptionDefinition> - .middleware(config, lws) ⇒
function|Array.<function()>
- MiddlewarePlugin ⏏
MiddlewarePlugin ⏏
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. |