koa-lite/examples/templates.js

39 lines
552 B
JavaScript
Raw Permalink Normal View History

2013-09-06 14:55:01 +00:00
var views = require('co-views');
var koa = require('..');
var app = koa();
// setup views
var render = views('examples/templates', {
ext: 'ejs'
});
// dummy data
var user = {
name: {
first: 'Tobi',
last: 'Holowaychuk'
},
species: 'ferret',
age: 3
};
// logger
app.use(function *logger(next){
var start = new Date;
yield next;
var ms = new Date - start;
console.log('%s %s - %s', this.method, this.url, ms);
2013-09-06 14:55:01 +00:00
});
// render
app.use(function *(){
this.body = yield render('user', { user: user });
2013-09-06 14:55:01 +00:00
})
app.listen(4000);