koa-json-body
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -1,20 +0,20 @@ | ||
'use strict'; | ||
'use strict' | ||
const body = require('co-body'); | ||
const body = require('co-body') | ||
module.exports = function(opts) { | ||
opts = opts || { strict: true }; | ||
module.exports = function (opts) { | ||
opts = opts || { strict: true } | ||
return (ctx, next) => { | ||
if (ctx.method === 'GET' || ctx.method === 'DELETE') { | ||
return next(); | ||
return next() | ||
} | ||
return body.json(ctx.req, opts).then((body) => { | ||
ctx.request.body = body; | ||
return next(); | ||
ctx.request.body = body | ||
return next() | ||
}, (err) => { | ||
return next(err); | ||
}); | ||
}; | ||
}; | ||
return next(err) | ||
}) | ||
} | ||
} |
{ | ||
"name": "koa-json-body", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "koa middleware to parse json request bodies", | ||
@@ -34,8 +34,5 @@ "main": "lib/index.js", | ||
"koa": "next", | ||
"mocha": "^2.3.3", | ||
"supertest": "^1.1.0" | ||
}, | ||
"peerDependencies": { | ||
"koa": "next" | ||
"mocha": "^3.2.0", | ||
"supertest": "^2.0.1" | ||
} | ||
} |
@@ -6,2 +6,4 @@ koa-json-body | ||
[![Dependency Status](https://img.shields.io/david/venables/koa-json-body/master.svg?style=flat-square)](https://david-dm.org/venables/koa-json-body) | ||
[![Build Status](https://img.shields.io/travis/venables/koa-json-body/master.svg?style=flat-square)](https://travis-ci.org/venables/koa-json-body) | ||
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
[![Downloads](https://img.shields.io/npm/dm/koa-json-body.svg?style=flat-square)](https://www.npmjs.com/package/koa-json-body) | ||
@@ -33,9 +35,9 @@ | ||
```javascript | ||
var jsonBody = require('koa-json-body'); | ||
var jsonBody = require('koa-json-body') | ||
app.use(jsonBody({ limit: '10kb' })); | ||
app.use(jsonBody({ limit: '10kb' })) | ||
app.use(function(ctx, next) { | ||
console.log(ctx.request.body); | ||
}); | ||
app.use(function (ctx, next) { | ||
console.log(ctx.request.body) | ||
}) | ||
``` | ||
@@ -46,7 +48,7 @@ | ||
```javascript | ||
var jsonBody = require('koa-json-body')({ limit: '10kb' }); | ||
var jsonBody = require('koa-json-body')({ limit: '10kb' }) | ||
app.post('/users', jsonBody, function(ctx, next) { | ||
console.log(ctx.request.body); | ||
}); | ||
app.post('/users', jsonBody, function (ctx, next) { | ||
console.log(ctx.request.body) | ||
}) | ||
``` | ||
@@ -53,0 +55,0 @@ |
@@ -1,31 +0,33 @@ | ||
'use strict'; | ||
'use strict' | ||
const body = require('../'); | ||
const Koa = require('koa'); | ||
const request = require('supertest'); | ||
/* eslint-env mocha */ | ||
describe('integration', function() { | ||
let app; | ||
const body = require('../') | ||
const Koa = require('koa') | ||
const request = require('supertest') | ||
before(function() { | ||
app = new Koa(); | ||
app.use(body()); | ||
app.use( ctx => { | ||
ctx.body = ctx.request.body; | ||
}); | ||
}); | ||
describe('integration', function () { | ||
let app | ||
it('does nothing on a GET request', function(done) { | ||
before(function () { | ||
app = new Koa() | ||
app.use(body()) | ||
app.use((ctx) => { | ||
ctx.body = ctx.request.body | ||
}) | ||
}) | ||
it('does nothing on a GET request', function (done) { | ||
request(app.listen()) | ||
.get('/') | ||
.expect(204, done); | ||
}); | ||
.expect(204, done) | ||
}) | ||
it('does nothing on a DELETE request', function(done) { | ||
it('does nothing on a DELETE request', function (done) { | ||
request(app.listen()) | ||
.delete('/') | ||
.expect(204, done); | ||
}); | ||
.expect(204, done) | ||
}) | ||
it('parses JSON and assigns it to ctx.request.body', function(done) { | ||
it('parses JSON and assigns it to ctx.request.body', function (done) { | ||
request(app.listen()) | ||
@@ -36,6 +38,6 @@ .post('/') | ||
}) | ||
.expect(200, { something: 'awesome' }, done); | ||
}); | ||
.expect(200, { something: 'awesome' }, done) | ||
}) | ||
it('silently handles invalid JSON', function(done) { | ||
it('silently handles invalid JSON', function (done) { | ||
request(app.listen()) | ||
@@ -46,4 +48,4 @@ .post('/') | ||
.send('{ "not": "json"') | ||
.expect(204, done); | ||
}); | ||
}); | ||
.expect(204, done) | ||
}) | ||
}) |
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
22415
1
7
57
63