egg-blueprint
Routing decorator for eggjs
Usage
For Install
npm install --save egg-blueprint
Setup
In router.ts
//router.ts
Prefix Url Globally
//router.ts //controller.ts @bp //===>>/api/user async { thisctxbody = 'hello,egg-blueprint' }
Prefix Url For Controller
//controller.ts bpprefix'/prefixtest' 'index' @bp //===>>/prefixtest/user async { thisctxbody = 'hello,egg-blueprint' }
NOTICE 1: bp.prefix
is not a decorator function. The first argument is prefix url, the second is ***the class name of this controller.
NOTICE 2: If you have already setup a global prefix option
,controller prefix function will do the next:
//router.ts //controller.tsbpprefix'/prefixtest' 'index' @bp //===>>/api/prefixtest/user async { thisctxbody = 'hello,egg-blueprint' }
Start Routing
@bp async { thisctxbody = 'hello,egg-blueprint' } @bp async { thisctxbody = 'hello,post,egg-blueprint' } ...
Adding Parmas
@bp async { console thisctxbody = thisctxparams'bar' }
Router Middleware
Router middleware will run before the target function.
Example
// some-controller.ts
- middleware Params:
Ctx:Context
andctl: Controller
, in this case,ctl
isTestController
,not the originalController
- if middleware returns
false
,the target function will not run, onlyfalse
can stop the whole middleware stack. the target function will continue if returnstrue
orundefined
.
Quick CRUD
@bp async { thisctxbody = 'hello,egg-blueprint' } async { thisctxbody = 'hello,post,egg-blueprint' } async { thisctxbody = 'hello,egg-blueprint' } async { thisctxbody = 'hello,egg-blueprint' }
The MIT License (MIT)
Copyright (c) ZhengFang snakegear@163.com