Changing static content directory <p>I am trying to set the express.static path to something different based on a session variable. The relevant code is below.</p> <pre><code>app.use( '/', function(req, res, next ) { if ( req.session.loggedIn ) { console.log("loggedIn : " + req.session.loggedIn); app.use('/', express.static(__dirname + '/private')); next(); } else { console.log("not logged in."); app.use('/', express.static(__dirname + '/public')); next(); } }); </code></pre> <p>When I start the application, I begin with not having req.session.loggedIn set. So it will use the static content in the /public directory (which contains an angular powered application for public users.) I then do a login (code below)</p> <pre><code>app.post('/login', function( req, res ) { req.session.loggedIn = true; var message = {}; message.success = true; message.text = "Logging you in..."; res.json(message); }); </code></pre> <p>Which sets the req.session.loggedIn variable to be true. I then hit refresh on the page (and have tried hard refresh, and cache clear/refresh as well). The console.log tells me "loggedIn : true" as expected, however it does NOT load the static content from the /private directory. It instead continues to load from the /public directory.</p> <p>Can anyone shed light on this issue?</p>