Comparing version 0.15.0 to 0.15.1
@@ -6,3 +6,2 @@ /* eslint-disable no-useless-return */ | ||
const runHooks = require('fastseries')() | ||
const jsonParser = require('body/json') | ||
const validation = require('./validation') | ||
@@ -37,3 +36,3 @@ const validateSchema = validation.validate | ||
if (req.headers['content-type'].indexOf('application/json') > -1) { | ||
return jsonParser(req, bodyParsed(handle, params, req, res)) | ||
return jsonBody(req, res, params, handle) | ||
// custom parser for a given content type | ||
@@ -54,3 +53,3 @@ } else if (handle.contentTypeParser.fastHasHeader(req.headers['content-type'])) { | ||
if (req.headers['content-type'] && req.headers['content-type'].indexOf('application/json') > -1) { | ||
return jsonParser(req, bodyParsed(handle, params, req, res)) | ||
return jsonBody(req, res, params, handle) | ||
// custom parser fir a given content type | ||
@@ -72,13 +71,32 @@ } else if (handle.contentTypeParser.fastHasHeader(req.headers['content-type'])) { | ||
function bodyParsed (handle, params, req, res) { | ||
function parsed (err, body) { | ||
if (err) { | ||
res.statusCode = 422 | ||
setImmediate(wrapResEnd, res) | ||
return | ||
function jsonBody (req, res, params, handle) { | ||
var body = '' | ||
req.on('error', onError) | ||
req.on('data', onData) | ||
req.on('end', onEnd) | ||
function onError (err) { | ||
jsonBodyParsed(err, null, req, res, params, handle) | ||
} | ||
function onData (chunk) { | ||
body += chunk | ||
} | ||
function onEnd () { | ||
setImmediate(parse, body) | ||
} | ||
function parse (json) { | ||
try { | ||
jsonBodyParsed(null, JSON.parse(body), req, res, params, handle) | ||
} catch (err) { | ||
jsonBodyParsed(err, null, req, res, params, handle) | ||
} | ||
handler(handle, params, req, res, body, urlUtil.parse(req.url, true).query) | ||
} | ||
} | ||
return parsed | ||
function jsonBodyParsed (err, body, req, res, params, handle) { | ||
if (err) { | ||
res.statusCode = 422 | ||
setImmediate(wrapResEnd, res) | ||
return | ||
} | ||
handler(handle, params, req, res, body, urlUtil.parse(req.url, true).query) | ||
} | ||
@@ -131,2 +149,2 @@ | ||
module.exports = build | ||
module.exports[Symbol.for('internals')] = { bodyParsed, routerHandler, handler } | ||
module.exports[Symbol.for('internals')] = { jsonBody, jsonBodyParsed, routerHandler, handler } |
{ | ||
"name": "fastify", | ||
"version": "0.15.0", | ||
"version": "0.15.1", | ||
"description": "Fast and low overhead web framework, for Node.js", | ||
@@ -41,2 +41,3 @@ "main": "fastify.js", | ||
"express": "^4.15.2", | ||
"fast-json-body": "^1.1.0", | ||
"fastify-plugin": "^0.1.0", | ||
@@ -64,3 +65,2 @@ "frameguard": "^3.0.0", | ||
"avvio": "^0.6.1", | ||
"body": "^5.1.0", | ||
"fast-json-stringify": "^0.10.4", | ||
@@ -67,0 +67,0 @@ "fast-safe-stringify": "^1.1.13", |
@@ -62,2 +62,6 @@ <div align="center"> | ||
Swagger documentation generator for Fastify | ||
- [`fastify-multipart`](https://github.com/fastify/fastify-multipart) | ||
Multipart support for Fastify | ||
- [`fastify-bearer-auth`](https://github.com/jsumners/fastify-bearer-auth) | ||
Bearer auth plugin for Fastify | ||
- *More coming soon* | ||
@@ -64,0 +68,0 @@ |
@@ -7,3 +7,3 @@ 'use strict' | ||
const Fastify = require('..') | ||
const jsonParser = require('body/json') | ||
const jsonParser = require('fast-json-body') | ||
@@ -10,0 +10,0 @@ test('contentTypeParser method should exist', t => { |
@@ -24,8 +24,2 @@ /* eslint-disable no-useless-return */ | ||
test('bodyParsed function', t => { | ||
t.plan(1) | ||
const parsed = internals.bodyParsed(null, null, null, null) | ||
t.is(typeof parsed, 'function') | ||
}) | ||
test('handler function - invalid schema', t => { | ||
@@ -32,0 +26,0 @@ t.plan(2) |
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
155708
10
4184
96
24
- Removedbody@^5.1.0
- Removedbody@5.1.0(transitive)
- Removedbytes@1.0.0(transitive)
- Removedcontinuable-cache@0.3.1(transitive)
- Removederror@7.2.1(transitive)
- Removedraw-body@1.1.7(transitive)
- Removedsafe-json-parse@1.0.1(transitive)
- Removedstring-template@0.2.1(transitive)
- Removedstring_decoder@0.10.31(transitive)