Permalink
Browse files

Added cookieSession() example

  • Loading branch information...
1 parent 6a4b322 commit 6b5233fc033fed20bbcf25dea0f3bcd511d8e307 @tj tj committed Feb 18, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 examples/cookieSession.js
View
@@ -0,0 +1,28 @@
+
+var connect = require('../')
+ , http = require('http');
+
+var app = connect()
+ .use(connect.logger('dev'))
+ .use(connect.cookieParser('some secret'))
+ .use(connect.cookieSession())
+ .use(clear)
+ .use(counter);
+
+function clear(req, res, next) {
+ if ('/clear' != req.url) return next();
+ req.session = null;
+ res.statusCode = 302;
+ res.setHeader('Location', '/');
+ res.end();
+}
+
+function counter(req, res) {
+ req.session.count = req.session.count || 0;
+ var n = req.session.count++;
+ res.end('<p>hits: ' + n + '</p>'
+ + '<p><a href="/clear">clear session</a></p>');
+}
+
+http.createServer(app).listen(3000);
+console.log('Server listening on port 3000');

0 comments on commit 6b5233f

Please sign in to comment.