add co-body to blog example

This commit is contained in:
TJ Holowaychuk 2013-11-27 23:03:15 -08:00
parent 38ce7c1559
commit 1b9960a28e
2 changed files with 3 additions and 23 deletions

View file

@ -7,6 +7,7 @@ var render = require('./lib/render');
var logger = require('koa-logger');
var route = require('koa-route');
var views = require('co-views');
var parse = require('co-body');
var koa = require('../..');
var app = koa();
@ -65,28 +66,6 @@ function *create() {
this.redirect('/');
}
// TODO: use a lib...
var qs = require('querystring');
function parse(ctx) {
return function(done){
var buf = '';
var req = ctx.req;
req.setEncoding('utf8');
req.on('data', function(chunk){ buf += chunk });
req.on('end', function(){
try {
done(null, qs.parse(buf));
} catch (err){
err.body = buf;
err.status = 400;
done(err);
}
});
}
}
// listen
app.listen(3000);

View file

@ -42,7 +42,8 @@
"koa-static": "~1.2.0",
"co-busboy": "git://github.com/cojs/busboy",
"koa-route": "~1.0.2",
"swig": "~1.1.0"
"swig": "~1.1.0",
"co-body": "0.0.1"
},
"engines": {
"node": "> 0.11.4"