mirror of
https://github.com/danbulant/koa-plugins
synced 2026-06-24 08:51:44 +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 |
|
| enabled | Whether the plugin is enabled and should be used |
|
||||||
| exec | Function to call when plugin is enabled and request matches rules |
|
| 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.|
|
| 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`:
|
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"){
|
if(typeof e == "function"){
|
||||||
e(this);
|
e(this);
|
||||||
} else {
|
} else {
|
||||||
|
if(e.native){
|
||||||
|
return app.use(e.exec);
|
||||||
|
}
|
||||||
if(!e.enabled || !e.exec)continue;
|
if(!e.enabled || !e.exec)continue;
|
||||||
this._plugins.push(e);
|
this._plugins.push(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue