Add native plugins

This commit is contained in:
Daniel Bulant 2020-03-01 19:24:44 +01:00
parent 9f1cb532e5
commit 0c1bdce0f1
2 changed files with 4 additions and 0 deletions

View file

@ -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`:

View file

@ -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);
}