Skip to content

Commit 6ca65ef

Browse files
JHotterbeekxtypicode
authored andcommitted
typicode#415 Missing body for POST request in middleware (typicode#576)
* 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
1 parent b9f63b9 commit 6ca65ef

File tree

4 files changed

+321
-298
lines changed

4 files changed

+321
-298
lines changed

src/cli/run.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ function createApp(source, object, routes, middlewares, argv) {
5656
logger: !argv.quiet,
5757
readOnly: argv.readOnly,
5858
noCors: argv.noCors,
59-
noGzip: argv.noGzip
59+
noGzip: argv.noGzip,
60+
bodyParser: true
6061
}
6162

6263
if (argv.static) {

src/server/defaults.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const cors = require('cors')
66
const compression = require('compression')
77
const errorhandler = require('errorhandler')
88
const objectAssign = require('object-assign')
9+
const bodyParser = require('./body-parser')
910

1011
module.exports = function(opts) {
1112
const userDir = path.join(process.cwd(), 'public')
@@ -64,5 +65,10 @@ module.exports = function(opts) {
6465
})
6566
}
6667

68+
// Add middlewares
69+
if (opts.bodyParser) {
70+
arr.push(bodyParser)
71+
}
72+
6773
return arr
6874
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function(req, res, next) {
2+
res.header('name', req.body.name)
3+
next()
4+
}

0 commit comments

Comments
 (0)