mirror of
https://github.com/typicode/json-server.git
synced 2025-08-01 06:34:02 +08:00
* Missing postbody in middleware Added body parser to server defaults. * Test name change Capitol letter is now lower case * Missing postbody in middleware Added body parser to server defaults. * Test name change Capitol letter is now lower case * Added postbody as option to defaults * Missing postbody in middleware Added body parser to server defaults. * Test name change Capitol letter is now lower case * Missing postbody in middleware Added body parser to server defaults. * Added postbody as option to defaults * Setting bodyParser as enabled by default for cli
This commit is contained in:
@ -56,7 +56,8 @@ function createApp(source, object, routes, middlewares, argv) {
|
|||||||
logger: !argv.quiet,
|
logger: !argv.quiet,
|
||||||
readOnly: argv.readOnly,
|
readOnly: argv.readOnly,
|
||||||
noCors: argv.noCors,
|
noCors: argv.noCors,
|
||||||
noGzip: argv.noGzip
|
noGzip: argv.noGzip,
|
||||||
|
bodyParser: true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.static) {
|
if (argv.static) {
|
||||||
|
@ -6,6 +6,7 @@ const cors = require('cors')
|
|||||||
const compression = require('compression')
|
const compression = require('compression')
|
||||||
const errorhandler = require('errorhandler')
|
const errorhandler = require('errorhandler')
|
||||||
const objectAssign = require('object-assign')
|
const objectAssign = require('object-assign')
|
||||||
|
const bodyParser = require('./body-parser')
|
||||||
|
|
||||||
module.exports = function(opts) {
|
module.exports = function(opts) {
|
||||||
const userDir = path.join(process.cwd(), 'public')
|
const userDir = path.join(process.cwd(), 'public')
|
||||||
@ -64,5 +65,10 @@ module.exports = function(opts) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add middlewares
|
||||||
|
if (opts.bodyParser) {
|
||||||
|
arr.push(bodyParser)
|
||||||
|
}
|
||||||
|
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
|
4
test/cli/fixtures/middlewares/postbody.js
Normal file
4
test/cli/fixtures/middlewares/postbody.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module.exports = function(req, res, next) {
|
||||||
|
res.header('name', req.body.name)
|
||||||
|
next()
|
||||||
|
}
|
@ -14,7 +14,8 @@ let PORT = 3100
|
|||||||
|
|
||||||
const middlewareFiles = {
|
const middlewareFiles = {
|
||||||
en: './fixtures/middlewares/en.js',
|
en: './fixtures/middlewares/en.js',
|
||||||
jp: './fixtures/middlewares/jp.js'
|
jp: './fixtures/middlewares/jp.js',
|
||||||
|
postbody: './fixtures/middlewares/postbody.js'
|
||||||
}
|
}
|
||||||
|
|
||||||
const bin = path.join(__dirname, '../../lib/cli/bin')
|
const bin = path.join(__dirname, '../../lib/cli/bin')
|
||||||
@ -162,6 +163,17 @@ describe('cli', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('db.json -m postbody-middleware.js', () => {
|
||||||
|
beforeEach(done => {
|
||||||
|
child = cli([dbFile, '-m', middlewareFiles.postbody])
|
||||||
|
serverReady(PORT, done)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should have post body in middleware', done => {
|
||||||
|
request.post('/posts').send({ name: 'test' }).expect('name', 'test', done)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('db.json -d 1000', () => {
|
describe('db.json -d 1000', () => {
|
||||||
beforeEach(done => {
|
beforeEach(done => {
|
||||||
child = cli([dbFile, '-d', 1000])
|
child = cli([dbFile, '-d', 1000])
|
||||||
|
Reference in New Issue
Block a user