aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/cache.js
blob: 1b621f6dc1dd929b4927d0ffbd131475e06efce7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict'

const cacheMiddleware = {
  cache: cache
}

function cache (cache) {
  return function (req, res, next) {
    // If we want explicitly a cache
    // Or if we don't specify if we want a cache or no and we are in production
    if (cache === true || (cache !== false && process.env.NODE_ENV === 'production')) {
      res.setHeader('Cache-Control', 'public')
    } else {
      res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
    }

    next()
  }
}

// ---------------------------------------------------------------------------

module.exports = cacheMiddleware