Created
June 1, 2011 10:48
-
-
Save jeromeetienne/1002105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// attempts to get flash/session accessible in any template | |
// - this middleware function fails and keep producing 'Error: req.flash() requires sessions' | |
// - this middleware has been place *after* session middleware in the stack | |
app.use(function(req,res, next){ | |
console.log("flash middleware") | |
res.locals({ | |
session : req.session, | |
flash : req.flash() | |
}); | |
}); |
@mhuggins Basically, what I've ended doing is this:
var app = express.createServer(
express.bodyParser(),
express.cookieParser('secretKey'),
express.session({secret: 'secretKey'})
);
Then:
app.dynamicHelpers({
flash: function(req,res){
return req.flash();
}
});
Check that I'm not passing those params inside app.configure()
, I'm setting that when I create the express
server.
@AlejandroMG, thx for the tip; works well
thanks @AlejandroMG, I'm was with "req.flash() requires sessions" error too, and this works for me as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting this error too despite including the following in my code:
Any luck getting it to work?