add co example

This commit is contained in:
TJ Holowaychuk 2013-09-02 19:28:54 -07:00
parent a79bfe3329
commit 1680639232
2 changed files with 24 additions and 2 deletions

22
examples/co.js Normal file
View file

@ -0,0 +1,22 @@
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);

View file

@ -20,7 +20,6 @@
"rack" "rack"
], ],
"repository": "koajs/koa", "repository": "koajs/koa",
"author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"co": "1.5.1", "co": "1.5.1",
@ -35,7 +34,8 @@
"bytes": "*", "bytes": "*",
"should": "1.2.2", "should": "1.2.2",
"mocha": "1.12.0", "mocha": "1.12.0",
"supertest": "0.7.1" "supertest": "0.7.1",
"co-fs": "~1.0.1"
}, },
"engines": { "engines": {
"node": "> 0.11.4" "node": "> 0.11.4"