aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'middlewares')
-rw-r--r--middlewares/cache.js25
-rw-r--r--middlewares/index.js5
-rw-r--r--middlewares/secure.js (renamed from middlewares/misc.js)19
3 files changed, 30 insertions, 19 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})()
diff --git a/middlewares/index.js b/middlewares/index.js
index 311dfb6d2..bfe325b1e 100644
--- a/middlewares/index.js
+++ b/middlewares/index.js
@@ -2,8 +2,9 @@
2 'use strict' 2 'use strict'
3 3
4 var middlewares = { 4 var middlewares = {
5 misc: require('./misc'), 5 cache: require('./cache'),
6 reqValidators: require('./reqValidators') 6 reqValidators: require('./reqValidators'),
7 secure: require('./secure')
7 } 8 }
8 9
9 // --------------------------------------------------------------------------- 10 // ---------------------------------------------------------------------------
diff --git a/middlewares/misc.js b/middlewares/secure.js
index cc4e2e8a4..99ac9cdae 100644
--- a/middlewares/misc.js
+++ b/middlewares/secure.js
@@ -8,25 +8,10 @@
8 var Pods = require('../models/pods') 8 var Pods = require('../models/pods')
9 var utils = require('../helpers/utils') 9 var utils = require('../helpers/utils')
10 10
11 var miscMiddleware = { 11 var secureMiddleware = {
12 cache: cache,
13 decryptBody: decryptBody 12 decryptBody: decryptBody
14 } 13 }
15 14
16 function cache (cache) {
17 return function (req, res, next) {
18 // If we want explicitly a cache
19 // Or if we don't specify if we want a cache or no and we are in production
20 if (cache === true || (cache !== false && process.env.NODE_ENV === 'production')) {
21 res.setHeader('Cache-Control', 'public')
22 } else {
23 res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
24 }
25
26 next()
27 }
28 }
29
30 function decryptBody (req, res, next) { 15 function decryptBody (req, res, next) {
31 var url = req.body.signature.url 16 var url = req.body.signature.url
32 Pods.findByUrl(url, function (err, pod) { 17 Pods.findByUrl(url, function (err, pod) {
@@ -61,5 +46,5 @@
61 46
62 // --------------------------------------------------------------------------- 47 // ---------------------------------------------------------------------------
63 48
64 module.exports = miscMiddleware 49 module.exports = secureMiddleware
65})() 50})()