1
0
Fork 0
peertube/server/middlewares/cache.js
2016-03-07 11:33:59 +01:00

23 lines
608 B
JavaScript

'use strict'
var 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