Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created October 27, 2013 01:11
Show Gist options
  • Save dhigginbotham/7176742 to your computer and use it in GitHub Desktop.
Save dhigginbotham/7176742 to your computer and use it in GitHub Desktop.
my req.flash replacement for express
module.exports = (req, res, next) ->
# check for existence of deprecated `req.flash`
if req.hasOwnProperty('flash') == true and typeof req.flash == 'object'
res.locals.flash = req.flash
if req.session.hasOwnProperty('messages') == true
res.locals.flash = req.session.messages
delete req.session.messages
return next()
module.exports = function (req, res, next) {
// check for existence of deprecated `req.flash`
if ((req.hasOwnProperty('flash')) && (typeof req.flash == 'object')) {
res.locals.flash = req.flash;
};
if (req.session.hasOwnProperty('messages')) {
res.locals.flash = req.session.messages;
delete req.session.messages;
};
return next();
}
@dhigginbotham
Copy link
Author

then you use it in your app.use block:

var flash = require('./pathTo/flash');
app.use(flash);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment