2

次のようなルートの配列があるとします。

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)。私は何を間違っていますか?

4

1 に答える 1