造了个小轮子,支持嵌套和中间件调用的Router
支持嵌套路由和链式调用:
// Nested routes
let admin_router = router.route('/admin', function *(next) {
let hasLogin = yield this.checkSession() // Check session somehow
if (hasLogin) {
yield* next
} else {
this.redirect(url_to_login)
}
})
admin_router.route('/::', function *(next, method) {
this.body = `Admin's ${method} operating`
})
虽然router模块以及有很多了,不过造轮子还是挺好玩的o( ̄▽ ̄)d