app.js 426 B

123456789101112131415161718
  1. var koa = require('koa');
  2. var hbs = require('..');
  3. var app = koa();
  4. // koa-hbs is middleware. Use it before you want to render a view
  5. app.use(hbs.middleware({
  6. viewPath: __dirname + '/views'
  7. }));
  8. // Render is attached to the koa context. Call this.render in your middleware
  9. // to attach your rendered html to the response body.
  10. app.use(function *() {
  11. yield this.render('main', {title: 'koa-hbs'});
  12. })
  13. app.listen(3000);