[express/connect.static] Set ‘Last-Modified’ to now to avoid 304 Not Modified

Why do I need this? The right answer is: I don’t need that trick!

The example below is just to show how to use routes to intercept requests to a static file.

Put router before static.

app.use(app.router);
app.use(express.static(__dirname + '/static'));

Add ‘/*’ handler (don’t forget to call next())

app.get('/*', function(req, res, next){ 
  res.setHeader('Last-Modified', (new Date()).toUTCString());
  next(); 
});

node.js Allow access only for logged in users

The reference to isLoggedIn in the route is an connect route middleware. Control is passed to the middleware function before the route function is called. Use isLoggedIn to verify that we have a user token in the session before we send the client the requested route.
If we do not have a user token in the session, then we redirect the client to the ‘/login’ route. This effectively locks down our routes from unauthenticated access.

function isLoggedIn(req, res, next) {
    if(req.session['FedTokenCookie']){
      next();
    }else{
      res.writeHead(301, {"Location":'/login'});
      res.end();
    }
};
app.get('/mails', isLoggedIn, function(req, res, next){
  ...;
});
app.get('/docs', isLoggedIn, function(req, res, next){
  ...;
});