【发布时间】:2015-10-23 02:22:38
【问题描述】:
假设我有一个如下所示的路线数组:
var routes = [
{
route: '/',
handler: function* () { this.body = yield render('home', template.home) }
},
{
route: '/about',
handler: function* () { this.body = yield render('about', template.about) }
}
];
app.use 他们的最佳方式是什么?我试过这样做(koa-route 作为我的中间件)是这样的:
Promise.each(routes, function(r) {
app.use(route.get(r.route, r.handler));
}).then(function() {
app.use(function *NotFound(next) {
this.status = 404;
this.body = 'not found';
});
});
但它似乎不起作用(我也尝试过普通的routes.forEach)。我做错了什么?
【问题讨论】:
标签: node.js promise generator koa co