File tree Expand file tree Collapse file tree 12 files changed +21
-35
lines changed Expand file tree Collapse file tree 12 files changed +21
-35
lines changed Original file line number Diff line number Diff line change 5
5
var express = require ( '../..' ) ;
6
6
var hash = require ( './pass' ) . hash ;
7
7
var bodyParser = require ( 'body-parser' ) ;
8
- var cookieParser = require ( 'cookie-parser' ) ;
9
8
var session = require ( 'express-session' ) ;
10
9
11
10
var app = module . exports = express ( ) ;
@@ -17,9 +16,8 @@ app.set('views', __dirname + '/views');
17
16
18
17
// middleware
19
18
20
- app . use ( bodyParser ( ) ) ;
21
- app . use ( cookieParser ( 'shhhh, very secret' ) ) ;
22
- app . use ( session ( ) ) ;
19
+ app . use ( bodyParser . urlencoded ( { extended : false } ) ) ;
20
+ app . use ( session ( { secret : 'shhhh, very secret' } ) ) ;
23
21
24
22
// Session-persisted message middleware
25
23
Original file line number Diff line number Diff line change 3
3
*/
4
4
5
5
var express = require ( '../../' ) ;
6
- var cookie - parser = require ( 'cookie-parser' ) ;
7
6
8
7
var app = module . exports = express ( ) ;
9
8
10
- // pass a secret to cookieParser() for signed cookies
11
- app . use ( cookieParser ( 'manny is cool' ) ) ;
12
-
13
9
// add req.session cookie support
14
- app . use ( cookieSession ( ) ) ;
10
+ app . use ( cookieSession ( { secret : 'manny is cool' } ) ) ;
15
11
16
12
// do something with the session
17
13
app . use ( count ) ;
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ if ('test' != process.env.NODE_ENV) app.use(logger(':method :url'));
17
17
// for signing the cookies.
18
18
app . use ( cookieParser ( 'my secret here' ) ) ;
19
19
20
- // parses json, x-www-form-urlencoded, and multipart/form-data
21
- app . use ( bodyParser ( ) ) ;
20
+ // parses x-www-form-urlencoded
21
+ app . use ( bodyParser . urlencoded ( { extended : false } ) ) ;
22
22
23
23
app . get ( '/' , function ( req , res ) {
24
24
if ( req . cookies . remember ) {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ app.use(express.static(__dirname + '/public'));
15
15
// api middleware
16
16
17
17
api . use ( logger ( 'dev' ) ) ;
18
- api . use ( bodyParser ( ) ) ;
18
+ api . use ( bodyParser . json ( ) ) ;
19
19
20
20
/**
21
21
* CORS support.
Original file line number Diff line number Diff line change 5
5
var express = require ( '../..' ) ;
6
6
var logger = require ( 'morgan' ) ;
7
7
var session = require ( 'express-session' ) ;
8
- var cookieParser = require ( 'cookie-parser' ) ;
9
8
var bodyParser = require ( 'body-parser' ) ;
10
9
var methodOverride = require ( 'method-override' ) ;
11
10
@@ -38,11 +37,10 @@ if (!module.parent) app.use(logger('dev'));
38
37
app . use ( express . static ( __dirname + '/public' ) ) ;
39
38
40
39
// session support
41
- app . use ( cookieParser ( 'some secret here' ) ) ;
42
- app . use ( session ( ) ) ;
40
+ app . use ( session ( { secret : 'some secret here' } ) ) ;
43
41
44
42
// parse request bodies (req.body)
45
- app . use ( bodyParser ( ) ) ;
43
+ app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
46
44
47
45
// allow overriding methods in query (?_method=put)
48
46
app . use ( methodOverride ( '_method' ) ) ;
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ app.set('views', __dirname + '/views');
18
18
app . use ( logger ( 'dev' ) ) ;
19
19
app . use ( methodOverride ( '_method' ) ) ;
20
20
app . use ( cookieParser ( ) ) ;
21
- app . use ( bodyParser ( ) ) ;
21
+ app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
22
22
app . use ( express . static ( __dirname + '/public' ) ) ;
23
23
24
24
// General
Original file line number Diff line number Diff line change 3
3
// $ redis-server
4
4
5
5
var express = require ( '../..' ) ;
6
- var cookieParser = require ( 'cookie-parser' ) ;
7
6
var session = require ( 'express-session' ) ;
8
7
9
8
var app = express ( ) ;
10
9
11
- // Required by session() middleware
12
- // pass the secret for signed cookies
13
- // (required by session())
14
- app . use ( cookieParser ( 'keyboard cat' ) ) ;
15
-
16
10
// Populates req.session
17
- app . use ( session ( ) ) ;
11
+ app . use ( session ( { secret : 'keyboard cat' } ) ) ;
18
12
19
13
app . get ( '/' , function ( req , res ) {
20
14
var body = '' ;
Original file line number Diff line number Diff line change 4
4
5
5
var express = require ( '../..' ) ;
6
6
var logger = require ( 'morgan' ) ;
7
- var cookieParser = require ( 'cookie-parser' ) ;
8
7
var session = require ( 'express-session' ) ;
9
8
10
9
// pass the express to the connect redis module
@@ -15,13 +14,8 @@ var app = express();
15
14
16
15
app . use ( logger ( 'dev' ) ) ;
17
16
18
- // Required by session() middleware
19
- // pass the secret for signed cookies
20
- // (required by session())
21
- app . use ( cookieParser ( 'keyboard cat' ) ) ;
22
-
23
17
// Populates req.session
24
- app . use ( session ( { store : new RedisStore } ) ) ;
18
+ app . use ( session ( { store : new RedisStore , secret : 'keyboard cat' } ) ) ;
25
19
26
20
app . get ( '/' , function ( req , res ) {
27
21
var body = '' ;
Original file line number Diff line number Diff line change 57
57
"marked" : " 0.3.2" ,
58
58
"multiparty" : " ~3.2.4" ,
59
59
"hjs" : " ~0.0.6" ,
60
- "body-parser" : " 1.3.0 " ,
61
- "cookie-parser" : " 1.1.0 " ,
62
- "express-session" : " 1.2.1 " ,
60
+ "body-parser" : " ~1.4.3 " ,
61
+ "cookie-parser" : " ~1.3.1 " ,
62
+ "express-session" : " ~1.5.0 " ,
63
63
"method-override" : " 2.0.2" ,
64
64
"morgan" : " 1.1.1" ,
65
65
"vhost" : " 2.0.0"
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ describe('cookies', function(){
22
22
it ( 'should respond to cookie' , function ( done ) {
23
23
request ( app )
24
24
. post ( '/' )
25
+ . type ( 'urlencoded' )
25
26
. send ( { remember : 1 } )
26
27
. expect ( 302 , function ( err , res ) {
27
28
if ( err ) return done ( err )
@@ -37,6 +38,7 @@ describe('cookies', function(){
37
38
it ( 'should clear cookie' , function ( done ) {
38
39
request ( app )
39
40
. post ( '/' )
41
+ . type ( 'urlencoded' )
40
42
. send ( { remember : 1 } )
41
43
. expect ( 302 , function ( err , res ) {
42
44
if ( err ) return done ( err )
@@ -53,6 +55,7 @@ describe('cookies', function(){
53
55
it ( 'should set a cookie' , function ( done ) {
54
56
request ( app )
55
57
. post ( '/' )
58
+ . type ( 'urlencoded' )
56
59
. send ( { remember : 1 } )
57
60
. expect ( 302 , function ( err , res ) {
58
61
res . headers . should . have . property ( 'set-cookie' )
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ describe('mvc', function(){
33
33
it ( 'should update the pet' , function ( done ) {
34
34
request ( app )
35
35
. put ( '/pet/3' )
36
+ . set ( 'Content-Type' , 'application/x-www-form-urlencoded' )
36
37
. send ( { pet : { name : 'Boots' } } )
37
38
. end ( function ( err , res ) {
38
39
if ( err ) return done ( err ) ;
@@ -102,6 +103,7 @@ describe('mvc', function(){
102
103
it ( 'should update the user' , function ( done ) {
103
104
request ( app )
104
105
. put ( '/user/1' )
106
+ . set ( 'Content-Type' , 'application/x-www-form-urlencoded' )
105
107
. send ( { user : { name : 'Tobo' } } )
106
108
. end ( function ( err , res ) {
107
109
if ( err ) return done ( err ) ;
@@ -116,6 +118,7 @@ describe('mvc', function(){
116
118
it ( 'should create a pet for user' , function ( done ) {
117
119
request ( app )
118
120
. post ( '/user/2/pet' )
121
+ . set ( 'Content-Type' , 'application/x-www-form-urlencoded' )
119
122
. send ( { pet : { name : 'Snickers' } } )
120
123
. expect ( 'Location' , '/user/2' )
121
124
. expect ( 302 , function ( err , res ) {
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ describe('req', function(){
34
34
it ( 'should check req.body' , function ( done ) {
35
35
var app = express ( ) ;
36
36
37
- app . use ( bodyParser ( ) ) ;
37
+ app . use ( bodyParser . json ( ) ) ;
38
38
39
39
app . use ( function ( req , res ) {
40
40
res . end ( req . param ( 'name' ) ) ;
You can’t perform that action at this time.
0 commit comments