Permalink
Browse files

added example for prev commit

  • Loading branch information...
1 parent c0cb44c commit 69c7f67168c48ac0b1115a3340a3aea1b8780369 @tj tj committed Feb 19, 2012
Showing with 25 additions and 1 deletion.
  1. +25 −1 examples/session.js
View
@@ -140,4 +140,28 @@ http.createServer(connect()
}
})).listen(3004);
-console.log('port 3004: Session#reload() demo');
+console.log('port 3004: Session#reload() demo');
+
+// by default sessions
+// last the duration of
+// a user-agent's own session,
+// aka while the browser is open.
+
+http.createServer(connect()
+ .use(connect.cookieParser('keyboard cat'))
+ .use(connect.session())
+ .use(connect.favicon())
+ .use(function(req, res, next){
+ var sess = req.session;
+ if (sess.views) {
+ res.setHeader('Content-Type', 'text/html');
+ res.write('<p>views: ' + sess.views + '</p>');
+ res.end();
+ sess.views++;
+ } else {
+ sess.views = 1;
+ res.end('welcome to the browser session demo. refresh!');
+ }
+ })).listen(3005);
+
+console.log('port 3005: browser-session length sessions');

0 comments on commit 69c7f67

Please sign in to comment.