Sha256: f519b8ad213166f9a358c2f781f7af9bdb0a9376fbb23ccef594158214c082b5

Contents?: true

Size: 1.03 KB

Versions: 17

Compression:

Stored size: 1.03 KB

Contents

var connect = require('../')
  , http = require('http');

var app = connect()
  .use(connect.logger('dev'))
  .use(connect.bodyParser())
  .use(connect.cookieParser())
  .use(connect.cookieSession({ secret: 'some secret' }))
  .use(post)
  .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 post(req, res, next) {
  if ('POST' != req.method) return next();
  req.session.name = req.body.name;
  next();
}

function counter(req, res) {
  req.session.count = req.session.count || 0;
  var n = req.session.count++;
  var name = req.session.name || 'Enter your name';
  res.end('<p>hits: ' + n + '</p>'
    + '<form method="post">'
    + '<p><input type="text" name="name" value="' + name + '" />'
    + '<input type="submit" value="Save" /></p>'
    + '</form>'
    + '<p><a href="/clear">clear session</a></p>');
}

http.createServer(app).listen(3000);
console.log('Server listening on port 3000');

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/examples/cookieSession.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/examples/cookieSession.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/examples/cookieSession.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/examples/cookieSession.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/examples/cookieSession.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/examples/cookieSession.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/examples/cookieSession.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/examples/cookieSession.js