Permalink
Browse files

Add express.json and express.urlencoded to parse bodies

closes #2211
  • Loading branch information...
dougwilson committed Sep 28, 2017
1 parent 86f5df0 commit c0136d8b48dd3526c58b2ad8666fb4b12b55116c
Showing with 11 additions and 14 deletions.
  1. +1 −0 History.md
  2. +1 −2 examples/auth/index.js
  3. +1 −2 examples/cookies/index.js
  4. +1 −2 examples/mvc/index.js
  5. +1 −2 examples/route-separation/index.js
  6. +4 −3 lib/express.js
  7. +1 −1 package.json
  8. +1 −2 test/req.param.js
View
@@ -2,6 +2,7 @@ unreleased
==========
* Add `"json escape"` setting for `res.json` and `res.jsonp`
* Add `express.json` and `express.urlencoded` to parse bodies
* Improve error message when autoloading invalid view engine
* Improve error messages when non-function provided as middleware
* Skip `Buffer` encoding when not generating ETag for small response
View
@@ -3,7 +3,6 @@
*/
var express = require('../..');
var bodyParser = require('body-parser');
var hash = require('pbkdf2-password')()
var path = require('path');
var session = require('express-session');
@@ -17,7 +16,7 @@ app.set('views', path.join(__dirname, 'views'));
// middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.urlencoded({ extended: false }))
app.use(session({
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
@@ -6,7 +6,6 @@ var express = require('../../');
var app = module.exports = express();
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
// custom log format
if ('test' != process.env.NODE_ENV) app.use(logger(':method :url'));
@@ -18,7 +17,7 @@ if ('test' != process.env.NODE_ENV) app.use(logger(':method :url'));
app.use(cookieParser('my secret here'));
// parses x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.urlencoded({ extended: false }))
app.get('/', function(req, res){
if (req.cookies.remember) {
View
@@ -6,7 +6,6 @@ var express = require('../..');
var logger = require('morgan');
var path = require('path');
var session = require('express-session');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var app = module.exports = express();
@@ -43,7 +42,7 @@ app.use(session({
}));
// parse request bodies (req.body)
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.urlencoded({ extended: true }))
// allow overriding methods in query (?_method=put)
app.use(methodOverride('_method'));
@@ -7,7 +7,6 @@ var path = require('path');
var app = express();
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var site = require('./site');
var post = require('./post');
@@ -27,7 +26,7 @@ if (!module.parent) {
app.use(methodOverride('_method'));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.urlencoded({ extended: true }))
app.use(express.static(path.join(__dirname, 'public')));
// General
View
@@ -12,6 +12,7 @@
* Module dependencies.
*/
var bodyParser = require('body-parser')
var EventEmitter = require('events').EventEmitter;
var mixin = require('merge-descriptors');
var proto = require('./application');
@@ -74,16 +75,16 @@ exports.Router = Router;
* Expose middleware
*/
exports.json = bodyParser.json
exports.query = require('./middleware/query');
exports.static = require('serve-static');
exports.urlencoded = bodyParser.urlencoded
/**
* Replace removed middleware with an appropriate error message.
*/
[
'json',
'urlencoded',
;[
'bodyParser',
'compress',
'cookieSession',
View
@@ -29,6 +29,7 @@
"dependencies": {
"accepts": "~1.3.4",
"array-flatten": "1.1.1",
"body-parser": "1.18.2",
"content-disposition": "0.5.2",
"content-type": "~1.0.4",
"cookie": "0.3.1",
@@ -59,7 +60,6 @@
},
"devDependencies": {
"after": "0.8.2",
"body-parser": "1.18.2",
"cookie-parser": "~1.4.3",
"cookie-session": "1.3.2",
"ejs": "2.5.7",
View
@@ -1,7 +1,6 @@
var express = require('../')
, request = require('supertest')
, bodyParser = require('body-parser')
describe('req', function(){
describe('.param(name, default)', function(){
@@ -34,7 +33,7 @@ describe('req', function(){
it('should check req.body', function(done){
var app = express();
app.use(bodyParser.json());
app.use(express.json())
app.use(function(req, res){
res.end(req.param('name'));

0 comments on commit c0136d8

Please sign in to comment.