From b9a3e09ad5a7673f64556d1dba122ed4c4fac980 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 7 Mar 2016 11:33:59 +0100 Subject: Prepare folders structure for angular app --- server/middlewares/cache.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 server/middlewares/cache.js (limited to 'server/middlewares/cache.js') diff --git a/server/middlewares/cache.js b/server/middlewares/cache.js new file mode 100644 index 000000000..0d3da0075 --- /dev/null +++ b/server/middlewares/cache.js @@ -0,0 +1,23 @@ +'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 -- cgit v1.2.3