From 1b9960a28eaa6e16254ba1bc78af99830a0c6414 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Wed, 27 Nov 2013 23:03:15 -0800 Subject: [PATCH] add co-body to blog example --- examples/blog/index.js | 23 +---------------------- package.json | 3 ++- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/examples/blog/index.js b/examples/blog/index.js index c6d2eb0..3ed8886 100644 --- a/examples/blog/index.js +++ b/examples/blog/index.js @@ -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); diff --git a/package.json b/package.json index 7331c68..9fcee63 100644 --- a/package.json +++ b/package.json @@ -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"