Tiaozhan Controller Extension
-
Get current route from
ctx.currentRoute
.ctx.currentRoute.Controller
for the target Controller class andctx.currentRoute.methodName
for the target method name. -
Return response by
return
.
$ npm i egg-tiaozhan-controller-extension --save
// {app_root}/config/plugin.js
exports.tiaozhanControllerExtension = {
enable: true,
package: 'egg-tiaozhan-controller-extension',
};
// {app_root}/config/config.default.js
exports.tiaozhanControllerExtension = {
};
No Configuration.
class HomeController extends Controller {
helloEgg() {
// 也可以在中间件等环境使用
const route = this.ctx.currentRoute;
// route.Controller === HomeController
// route.Controller.prototype === HomeController.prototype
// route.methodName === 'helloEgg'
}
}
class HomeController extends Controller {
helloEgg() {
// some code
}
}
// Need reflect-metadata
Reflect.defineMetadata('mykey', { meta: 123 }, HomeController.prototype);
class HomeController extends Controller {
simpleText() {
return 'hi, egg';
}
complexBody() {
return {
message: 'hi, egg',
};
}
}
Please open a PR.