koa-lite/examples/co.js
TJ Holowaychuk 2733c61d00 docs
2013-09-02 19:31:11 -07:00

22 lines
414 B
JavaScript

var koa = require('..');
var fs = require('co-fs');
var app = koa();
// read docs/*.md in parallel
// and return a joined response
app.use(function(){
return function *(){
var paths = yield fs.readdir('docs');
var files = yield paths.map(function(path){
return fs.readFile('docs/' + path, 'utf8');
});
this.type = 'markdown';
this.body = files.join('');
}
});
app.listen(3000);