I'm using express and I was trying to get connect-flash working, but it 
wouldn't work with my redirects. So I've decided to take another approach 
and that's just to roll my own middleware for session flashes. Has anyone 
had any experience on doing this? I tried to scaffold it but I'm running 
into the headers already being sent issue. How can I make this work?

/* 
* app.js
*/

app.configure(function() {
  app.use(express.cookieParser('keyboard cat'));
  app.use(express.session({ key: 'sid', cookie: { maxAge: 60000 }}));
  app.use(flashed);
  app.use(app.router);
});

function flashed(obj, req, res, next) {
  var type = obj[0],
      msg = obj[1];
  if (obj !== 'undefined') {
    req.session.flashType = obj[0];
    req.session.flashMsg = obj[1];
    res.locals.flashType = req.session.flashType;
    res.locals.flashMsg = req.session.flashMsg;
    delete req.session.flashType;
    delete req.session.flashMsg;
  }
  next();
}

app.get('/', function(req, res, next) {
flashed(['error', 'my default message'], req, res, next);
res.render('index');
});

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to