From 0c1bdce0f15caba7431f6c418e4fbf7f04008385 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Sun, 1 Mar 2020 19:24:44 +0100 Subject: [PATCH] Add native plugins --- README.md | 1 + hooks.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 3c99660..5c7aff6 100644 --- a/README.md +++ b/README.md @@ -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). 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`: diff --git a/hooks.js b/hooks.js index 29e8f67..e636da7 100644 --- a/hooks.js +++ b/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); }