-
-
Save jeromeetienne/1002105 to your computer and use it in GitHub Desktop.
| // 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() | |
| }); | |
| }); |
i think you need session in the express config. http://expressjs.com/guide.html#session-support
and before using flash, as shown in the example
Yeah! Actually I'm doing this...
var MemStore = require('connect').session.MemoryStore; app.configure(function() { app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.logger()); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(__dirname + '/public')); app.use(express.cookieParser()); app.use(express.session({ store: new MemStore({ reapInterval: 60000 * 10 }) , secret:"alejandromg"})); });
I'm getting this error too despite including the following in my code:
app.use(express.session({secret: 'foobar'}));
Any luck getting it to work?
@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.
Did you fix the
Error: req.flash() requires sessions? I don't know how to fix this error.