Comparing version 6.1.2 to 6.1.3
@@ -11,2 +11,8 @@ # appa change log | ||
## 6.1.3 - 2017-07-02 | ||
## Fixed | ||
- make it possible to skip body parsing with `{ parse: false }` option | ||
## 6.1.2 - 2017-02-25 | ||
@@ -13,0 +19,0 @@ |
33
index.js
@@ -73,3 +73,3 @@ var assert = require('assert') | ||
* @param {Object} options – options for the request handler | ||
* @param {Boolean} options.parseJSON – optionally disable JSON parsing of the body. Default: `true` | ||
* @param {Boolean} options.parse – optionally disable parsing of the body. Default: `true` | ||
* @param {Function} callback – the route handler | ||
@@ -91,3 +91,3 @@ * @example | ||
options.parseJSON = options.parseJSON === false ? options.parseJSON : true | ||
options.parse = options.parse === false ? options.parse : true | ||
@@ -98,15 +98,7 @@ return router.on(pathname, function (params, req, res, ctx) { | ||
function respond (req, res, ctx) { | ||
try { | ||
return callback(req, res, ctx) | ||
} catch (e) { | ||
return error(500, 'Internal server error', e).pipe(res) | ||
} | ||
} | ||
if (req.method === 'POST' || req.method === 'PUT' || req.method === 'PATCH') { | ||
function parse (req, options) { | ||
body(req, options, function (err, result) { | ||
if (err) return error(err.status, err.type).pipe(res) | ||
if (isType(req, ['json']) && options.parseJSON) { | ||
if (isType(req, ['json'])) { | ||
ctx.body = parseJSON(res, result) | ||
@@ -119,5 +111,18 @@ } else { | ||
}) | ||
} else { | ||
return respond(req, res, ctx) | ||
} | ||
function respond (req, res, ctx) { | ||
try { | ||
return callback(req, res, ctx) | ||
} catch (e) { | ||
return error(500, 'Internal server error', e).pipe(res) | ||
} | ||
} | ||
if (req.method === 'POST' || req.method === 'PUT' || req.method === 'PATCH') { | ||
if (options.parse === false) return respond(req, res, ctx) | ||
return parse(req, options) | ||
} | ||
return respond(req, res, ctx) | ||
}) | ||
@@ -124,0 +129,0 @@ } |
{ | ||
"name": "appa", | ||
"version": "6.1.2", | ||
"version": "6.1.3", | ||
"description": "Quickly create simple JSON API services.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61297
356