Skip to content

Commit

Permalink
update Readme and examples for new secret options
Browse files Browse the repository at this point in the history
cookieSession and session now accept a `secret` option. This is the
prefered way to use these middleware now so the Readme and examples are
updated accordingly.

cookieParser docs still indication signed cookie support just not for
the `session` middleware explicitly
  • Loading branch information
defunctzombie committed Jun 8, 2012
1 parent 5a85b18 commit 1e57e03
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Readme.md
Expand Up @@ -14,8 +14,8 @@ var app = connect()
.use(connect.logger('dev'))
.use(connect.static('public'))
.use(connect.directory('public'))
.use(connect.cookieParser('my secret here'))
.use(connect.session())
.use(connect.cookieParser())
.use(connect.session({ secret: 'my secret here' }))
.use(function(req, res){
res.end('Hello from Connect!\n');
});
Expand Down Expand Up @@ -129,4 +129,4 @@ then:

## License

View the [LICENSE](https://github.com/senchalabs/connect/blob/master/LICENSE) file. The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons used by the `directory` middleware created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
View the [LICENSE](https://github.com/senchalabs/connect/blob/master/LICENSE) file. The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons used by the `directory` middleware created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
6 changes: 3 additions & 3 deletions examples/cookieSession.js
Expand Up @@ -5,8 +5,8 @@ var connect = require('../')
var app = connect()
.use(connect.logger('dev'))
.use(connect.bodyParser())
.use(connect.cookieParser('some secret'))
.use(connect.cookieSession())
.use(connect.cookieParser())
.use(connect.cookieSession({ secret: 'some secret' }))
.use(post)
.use(clear)
.use(counter);
Expand Down Expand Up @@ -38,4 +38,4 @@ function counter(req, res) {
}

http.createServer(app).listen(3000);
console.log('Server listening on port 3000');
console.log('Server listening on port 3000');
6 changes: 3 additions & 3 deletions examples/csrf.js
Expand Up @@ -15,8 +15,8 @@ var form = '\n\
';

var app = connect()
.use(connect.cookieParser('keyboard cat'))
.use(connect.session())
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat' }))
.use(connect.bodyParser())
.use(connect.csrf())
.use(function(req, res, next){
Expand All @@ -33,4 +33,4 @@ var app = connect()
});

http.createServer(app).listen(3000);
console.log('Server listening on port 3000');
console.log('Server listening on port 3000');
25 changes: 13 additions & 12 deletions examples/session.js
Expand Up @@ -7,8 +7,8 @@ var connect = require('../')
// receive req.session

http.createServer(connect()
.use(connect.cookieParser('keyboard cat'))
.use(connect.session({ cookie: { maxAge: 60000 }}))
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
.use(connect.favicon())
.use(function(req, res, next){
var sess = req.session;
Expand All @@ -31,8 +31,9 @@ console.log('port 3000: 1 minute expiration demo');
try {
var RedisStore = require('connect-redis')(connect);
http.createServer(connect()
.use(connect.cookieParser('keyboard cat'))
.use(connect.cookieParser())
.use(connect.session({
secret: 'keyboard cat',
cookie: { maxAge: 60000 * 3 }
, store: new RedisStore
}))
Expand Down Expand Up @@ -64,10 +65,10 @@ try {
// conditional session support by simply
// wrapping middleware with middleware.

var sess = connect.session({ cookie: { maxAge: 5000 }});
var sess = connect.session({ secret: 'keyboard cat', cookie: { maxAge: 5000 }});

http.createServer(connect()
.use(connect.cookieParser('keyboard cat'))
.use(connect.cookieParser())
.use(function(req, res, next){
if ('/foo' == req.url || '/bar' == req.url) {
sess(req, res, next);
Expand All @@ -90,8 +91,8 @@ console.log('port 3002: conditional sessions');
// session data

http.createServer(connect()
.use(connect.cookieParser('keyboard cat'))
.use(connect.session({ cookie: { maxAge: 60000 }}))
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
.use(connect.favicon())
.use(function(req, res, next){
var sess = req.session
Expand Down Expand Up @@ -125,8 +126,8 @@ console.log('port 3003: Session#reload() demo');
// aka while the browser is open.

http.createServer(connect()
.use(connect.cookieParser('keyboard cat'))
.use(connect.session())
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat' }))
.use(connect.favicon())
.use(function(req, res, next){
var sess = req.session;
Expand All @@ -147,8 +148,8 @@ console.log('port 3004: browser-session length sessions');

http.createServer(connect()
.use(connect.bodyParser())
.use(connect.cookieParser('keyboard cat'))
.use(connect.session())
.use(connect.cookieParser())
.use(connect.session({ secret: 'keyboard cat' }))
.use(connect.favicon())
.use(function(req, res, next){
if ('POST' != req.method) return next();
Expand All @@ -168,4 +169,4 @@ http.createServer(connect()
+ '</form>');
})).listen(3005);

console.log('port 3005: browser-session length sessions persistence example');
console.log('port 3005: browser-session length sessions persistence example');
4 changes: 2 additions & 2 deletions lib/middleware/cookieParser.js
Expand Up @@ -20,12 +20,12 @@ var utils = require('./../utils')
* with an object keyed by the cookie names. Optionally
* you may enabled signed cookie support by passing
* a `secret` string, which assigns `req.secret` so
* it may be used by other middleware such as `session()`.
* it may be used by other middleware.
*
* Examples:
*
* connect()
* .use(connect.cookieParser('keyboard cat'))
* .use(connect.cookieParser('optional secret string'))
* .use(function(req, res, next){
* res.end(JSON.stringify(req.cookies));
* })
Expand Down

0 comments on commit 1e57e03

Please sign in to comment.