egg-hook
添加controller级别或者action级别中间件。
提供控制器级别 __before和__after这两个前后置action。
安装
$ npm i egg-hook --save
用法
启用插件
// {app_root}/config/plugin.jsexportshook = enable: true package: 'egg-hook';
启动自定义文件中添加hook
app.controllerHook(controllerKey,hook)
//app.jsapp;
app.actionHook(controllerKey,actionKey,hook)
//app.jsapp;
控制器前后置钩子
//app/controller/home.jsmodule { return Controller { console; const ctx=this; if!ctxisLogin return ctx;//skip index() and __after() } * { console; //ctx.preventNext() //skip __after() } { console; } }
应用场景
Questions & Suggestions
Please open an issue here.