Using babel enhance [koa-router][1].Add namespace and named middleware.
1.Named middleware
Basic usage:
var router = new Router();
var middlewareCount = 0;
var middlewareA = function *(next) {
middlewareCount++;
yield next;
};
var middlewareB = function *(next) {
middlewareCount++;
yield next;
};
router.registerMiddleware("A", middlewareA);
router.registerMiddleware("B", middlewareB);
router.get('/users/:id', {middleware: 'A|B'}, function *() {
this.body = { hello: 'world' };
});
2.Route group
Basic usage:
var router = new Router();
router.group({prefix: '/things/:thing_id'}, function() {
router.get('/', function *() {
this.body = 'test';
});
router.get('/users/:id', function *() {
this.body = 'test';
});
});
middleware group
var router = new Router();
router.group({middleware: 'A|B'}, function() {
router.get('/', function *() {
this.body = 'test';
});
router.get('/users/:id', function *() {
this.body = 'test';
});
});
- Controller maybe not
- CORS
- Metrics
- Consul support [1]:https://github.com/alexmingoia/koa-router