mirror of
https://github.com/danbulant/koa-plugins
synced 2026-06-10 01:50:38 +00:00
Add native plugins
This commit is contained in:
parent
9f1cb532e5
commit
0c1bdce0f1
2 changed files with 4 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ The plugin must export object or function. Object should contain these:
|
|||
| enabled | Whether the plugin is enabled and should be used |
|
||||
| exec | Function to call when plugin is enabled and request matches rules |
|
||||
| rules | Object containing rules to be passed before calling exec. Can be function, in which case the context is passed and must return boolean (or Promise<boolean>). If empty, automatically evaluates to true.|
|
||||
| Native | If native is selected, plugin is registered directly to koa. This means, that the exec gets also function `next` and ignores rules & enabled properties |
|
||||
|
||||
If the exported is function, it works as `multi-plugin`:
|
||||
|
||||
|
|
|
|||
3
hooks.js
3
hooks.js
|
|
@ -21,6 +21,9 @@ module.exports = class Hooks {
|
|||
if(typeof e == "function"){
|
||||
e(this);
|
||||
} else {
|
||||
if(e.native){
|
||||
return app.use(e.exec);
|
||||
}
|
||||
if(!e.enabled || !e.exec)continue;
|
||||
this._plugins.push(e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue