aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares/cache.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-02-04 21:16:27 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-02-04 21:23:06 +0100
commita5fa04b0cce851f680a45055f57ed2c3d22f1c82 (patch)
tree0749c4d6889d7cf250110f9ff59a8cd22ee8a480 /middlewares/cache.js
parentc173e56520b0fe4206b9ea8049b6add40bfeabcd (diff)
downloadPeerTube-a5fa04b0cce851f680a45055f57ed2c3d22f1c82.tar.gz
PeerTube-a5fa04b0cce851f680a45055f57ed2c3d22f1c82.tar.zst
PeerTube-a5fa04b0cce851f680a45055f57ed2c3d22f1c82.zip
Split misc middleware
Diffstat (limited to 'middlewares/cache.js')
-rw-r--r--middlewares/cache.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/middlewares/cache.js b/middlewares/cache.js
new file mode 100644
index 000000000..782165155
--- /dev/null
+++ b/middlewares/cache.js
@@ -0,0 +1,25 @@
1;(function () {
2 'use strict'
3
4 var cacheMiddleware = {
5 cache: cache
6 }
7
8 function cache (cache) {
9 return function (req, res, next) {
10 // If we want explicitly a cache
11 // Or if we don't specify if we want a cache or no and we are in production
12 if (cache === true || (cache !== false && process.env.NODE_ENV === 'production')) {
13 res.setHeader('Cache-Control', 'public')
14 } else {
15 res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
16 }
17
18 next()
19 }
20 }
21
22 // ---------------------------------------------------------------------------
23
24 module.exports = cacheMiddleware
25})()