Created
October 27, 2013 01:11
-
-
Save dhigginbotham/7176742 to your computer and use it in GitHub Desktop.
my req.flash replacement for express
This file contains hidden or 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
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() |
This file contains hidden or 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
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
then you use it in your app.use block:
var flash = require('./pathTo/flash');
app.use(flash);