Sha256: 1ad93af55843f0ab3a4e7e9575ae0baf056fee0c3920f8c96bac1f5ac49ca1f1

Contents?: true

Size: 1.83 KB

Versions: 26

Compression:

Stored size: 1.83 KB

Contents

/**
 * Module dependencies.
 */

var sys = require('sys'),
    MemoryStore = require('./../../lib/connect/middleware/session/memory'),
    Connect = require('./../../lib/connect');

// One minute
var minute = 60000;


var Server = module.exports = Connect.createServer(
    Connect.logger({ format: ':method :url' }),
    Connect.bodyDecoder(),
    Connect.cookieDecoder(),
    Connect.session({ store: new MemoryStore({ reapInterval: minute, maxAge: minute * 5 }) }),
    Connect.router(app),
    Connect.errorHandler({ dumpExceptions: true, showStack: true })
);

function app(app) {
    app.get('/', function(req, res){
        res.writeHead(200, { 'Content-Type': 'text/html' });
        // Fetch number of "online" users
        req.sessionStore.length(function(err, n){
            // User joined
            if (req.session.name) {
                res.write('<p>Welcome ' + req.session.name + '</p>');
            // User has not "joined", display the form
            } else {
                res.write('<form method="post">'
                    + 'Name: <input type="text" name="name"/>'
                    + '<input type="submit" value="Join" name="op" />'
                    + '</form>');
            }

            // Display online count
            res.end('<p>Online: ' + n + '</p>');
        });
    });
    app.get('/logout', function(req, res){
        req.session.regenerate(function(err){
            res.writeHead(302, { Location: '/' });
            res.end();
        });
    });
    app.post('/', function(req, res){
        switch (req.body.op) {
            case 'Join':
                req.session.regenerate(function(err){
                    var name = req.session.name = req.body.name;
                    res.writeHead(302, { Location: '/' });
                    res.end();
                });
                break;
        }
    });
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
vulcan-0.8.2 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.8.1 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.8.0 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.7.2 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.7.1 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.7.0 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.6.1 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.6.0 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.5.0 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.4.0 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.3.0 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.2.5 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.2.4 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.2.3 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.2.2 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.2.1 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.2.0 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.1.6 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.1.5 server/node_modules/connect-form/support/connect/examples/session/app.js
vulcan-0.1.4 server/node_modules/connect-form/support/connect/examples/session/app.js