From 0f80306c40c16f4b1d2b880576a05aa4b00891b6 Mon Sep 17 00:00:00 2001 From: Kyle Moore Date: Thu, 3 Aug 2017 16:02:24 -0400 Subject: [PATCH] Add options that are passed to connect-flash This allows one to initialize the middleware with unsafe:true and suppress flash when desired by setting req.flash to a no-op function. I use this in controllers to prevent breaking res.render when the session is being destroyed or is otherwise not initialized. --- lib/express-flash.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/express-flash.js b/lib/express-flash.js index ec1c80c..c549a07 100644 --- a/lib/express-flash.js +++ b/lib/express-flash.js @@ -8,7 +8,7 @@ * Module Dependencies */ -var connectFlash = require('connect-flash')(); +var connectFlash = require('connect-flash'); /** * Return a middleware function @@ -16,10 +16,10 @@ var connectFlash = require('connect-flash')(); * @return {Function} middleware function * @api public */ -exports = module.exports = function () { +exports = module.exports = function (options) { return function (req, res, next) { - connectFlash(req, res, function () { + connectFlash(options)(req, res, function () { // Proxy the render function so that the flash is // retrieved right before the render function is executed var render = res.render; diff --git a/package.json b/package.json index c829a1e..8fb15c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-flash", - "version": "0.0.2", + "version": "0.0.3", "description": "Flash Messages for your Express Application", "homepage": "https://github.com/RGBboy/express-flash", "keywords": ["express", "flash", "messages"],