title: Render jade template from middleware in node.js with express
body: <p>Instead of checking in every controller I want to use <code>app.all('*')</code> to check if the user is authenticated and it already works quite well. If the user is logged in I'm just calling <code>next()</code> and if he's not I'm calling another route to display the login page.</p>
  
  <p>So far so good, but it seems that rendering from that middleware callback function somehow messes up my paths, for example the stylesheet doesn't work and when I click on it in the page source I again land on the index page.</p>
  
  <p>To sum it up, this works and displays my styles:</p>
  
  <pre><code>app.get('/', function (req, res) {
      res.render('index', { title: 'Account Page' });
  });
  </code></pre>
  
  <p>while this does work partially, it only displayes the HTML without the styles from the stylesheet:</p>
  
  <pre><code>app.all('*', function (req, res) {
      app.set('loggedIn', controller.security.authenticationAction(req));
  
      if (app.get('loggedIn')) next(); // go on with '/' route
      else res.render('index', { title: 'Index Page' });
  });
  </code></pre>
  
  <p>This also displays the same HTML page (with another title though) just without the styles.
  This is my default config in the app.js:</p>
  
  <pre><code>app.all('*', function (req, res) { ... });
  
  // all environments
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
  app.use(express.cookieParser('keykeykey'));
  </code></pre>
  
  <p>Help!</p>