Skip to content

Instantly share code, notes, and snippets.

@thomseddon
Last active December 16, 2015 22:59
Show Gist options
  • Save thomseddon/5511325 to your computer and use it in GitHub Desktop.
Save thomseddon/5511325 to your computer and use it in GitHub Desktop.
Connect sessions only on certain routes
var session = express.session();
// Slightly Invasive
app.get('/home', session, routes.home);
app.get('/about', routes.about);
app.get('/faq', routes.faq);
// or
// Crude
var excludedPaths = ['/about', '/faq'];
app.use(function (req, res, next) {
if (excludedPaths.indexOf(req.url) >= 0) return next();
session(req, res, next);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment