| 473 | }) |
| 474 | |
| 475 | function createServer (opts) { |
| 476 | var _bodyParser = typeof opts !== 'function' |
| 477 | ? bodyParser.raw(opts) |
| 478 | : opts |
| 479 | |
| 480 | return http.createServer(function (req, res) { |
| 481 | _bodyParser(req, res, function (err) { |
| 482 | if (err) { |
| 483 | res.statusCode = err.status || 500 |
| 484 | res.end('[' + err.type + '] ' + err.message) |
| 485 | return |
| 486 | } |
| 487 | |
| 488 | if (Buffer.isBuffer(req.body)) { |
| 489 | res.end('buf:' + req.body.toString('hex')) |
| 490 | return |
| 491 | } |
| 492 | |
| 493 | res.end(JSON.stringify(req.body)) |
| 494 | }) |
| 495 | }) |
| 496 | } |
| 497 | |
| 498 | function tryRequire (name) { |
| 499 | try { |