queckezz / koa-views

Template rendering middleware for koa (hbs, swig, pug, anything! :sparkles:)
MIT License
710 stars 87 forks source link

Why do I have to call 'return' on ctx.render #118

Closed rkt2spc closed 6 years ago

rkt2spc commented 6 years ago

Why does this works:

app.use((ctx, next) => {
  return ctx.render('user', { user }); // return is important, I don't know why
});

and this doesn't:

app.use((ctx, next) => {
  ctx.render('user', { user }); // Response 404
});
int64ago commented 6 years ago

https://github.com/koajs/koa/blob/master/lib/application.js#L113

https://github.com/koajs/koa/blob/master/lib/application.js#L126

https://github.com/koajs/compose/blob/master/index.js#L42

The callback in use should be in synchronous (like async/await) or return a Promise