Skip to content

Instantly share code, notes, and snippets.

@Chunlin-Li
Created March 20, 2017 12:08
Show Gist options
  • Save Chunlin-Li/1f013483dff79f630cf3c92d9c2b1277 to your computer and use it in GitHub Desktop.
Save Chunlin-Li/1f013483dff79f630cf3c92d9c2b1277 to your computer and use it in GitHub Desktop.
co-body v5.0.3 reproduce
'use strict';
var koa = require('koa');
var bodyParse = require('koa-bodyparser');
var app = new koa();
app.use(function *(next) {
let bodyData = [];
this.req.on('data', (chunk) => {
bodyData.push(chunk);
});
this.req.on('end', () => {
this.req.rawBody = Buffer.concat(bodyData).toString();
});
return yield next;
});
app.use(bodyParse());
app.listen(2000, function() {
let data = JSON.stringify({foo:'bar'});
var request = require('http').request({
hostname: '127.0.0.1',
port: 2000,
method: 'POST',
path: '/foo',
headers: {
'Content-Type' : 'application/json',
}
}, function (resp) {
resp.pipe(process.stdout);
});
request.end(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment