I have an Express application with some routes, only two of them need to support sessions. I read everywhere that the middleware definition (app.use(express.session({...) ap
Don't use app.use(express.session({ ... }))
.
Instead, initialize the session middleware, save a reference to the resulting function then include it directly in the routes you want it on.
var express = require('express'),
app = express();
var session = express.session({
//session configuration
});
app.use(app.router);
// must come after app.use(app.router);
app.get('/your/route/here', session, function(req, res){
// code for route handler goes here
});
Slightly simpler than the answer included in the update (you don't need the wrapper function).