File size: 594 Bytes
cbc76af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import qs from 'query-string';

// add rx methods to express
export default function getExpressExtensions() {
  return function expressExtensions(req, res, next) {
    res.redirectWithFlash = uri => {
      const flash = req.flash();
      res.redirect(
        `${uri}?${qs.stringify(
          { messages: qs.stringify(flash, { arrayFormat: 'index' }) },
          { arrayFormat: 'index' }
        )}`
      );
    };
    res.sendFlash = (type, message) => {
      if (type && message) {
        req.flash(type, message);
      }
      return res.json(req.flash());
    };
    next();
  };
}