aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-13 16:13:00 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-13 16:13:00 +0200
commit5dda52c924763a889e98b4cf97c588b34ef01812 (patch)
tree0616e61d825dbfee6e0183555e47cdb7b1d7f472 /server
parent788a7e02029efae7c44bc4ec608493f67dac291a (diff)
downloadPeerTube-5dda52c924763a889e98b4cf97c588b34ef01812.tar.gz
PeerTube-5dda52c924763a889e98b4cf97c588b34ef01812.tar.zst
PeerTube-5dda52c924763a889e98b4cf97c588b34ef01812.zip
Remove the cache middleware
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/v1/pods.js9
-rw-r--r--server/controllers/api/v1/remoteVideos.js3
-rw-r--r--server/controllers/api/v1/users.js6
-rw-r--r--server/controllers/api/v1/videos.js11
-rw-r--r--server/middlewares/cache.js23
-rw-r--r--server/middlewares/index.js2
6 files changed, 11 insertions, 43 deletions
diff --git a/server/controllers/api/v1/pods.js b/server/controllers/api/v1/pods.js
index b16fea4f6..fd13034a2 100644
--- a/server/controllers/api/v1/pods.js
+++ b/server/controllers/api/v1/pods.js
@@ -5,7 +5,6 @@ const express = require('express')
5const logger = require('../../../helpers/logger') 5const logger = require('../../../helpers/logger')
6const friends = require('../../../lib/friends') 6const friends = require('../../../lib/friends')
7const middleware = require('../../../middlewares') 7const middleware = require('../../../middlewares')
8const cacheMiddleware = middleware.cache
9const Pods = require('../../../models/pods') 8const Pods = require('../../../models/pods')
10const reqValidator = middleware.reqValidators.pods 9const reqValidator = middleware.reqValidators.pods
11const secureMiddleware = middleware.secure 10const secureMiddleware = middleware.secure
@@ -15,10 +14,10 @@ const Videos = require('../../../models/videos')
15 14
16const router = express.Router() 15const router = express.Router()
17 16
18router.get('/', cacheMiddleware.cache(false), listPods) 17router.get('/', listPods)
19router.post('/', reqValidator.podsAdd, cacheMiddleware.cache(false), addPods) 18router.post('/', reqValidator.podsAdd, addPods)
20router.get('/makefriends', reqValidator.makeFriends, cacheMiddleware.cache(false), makeFriends) 19router.get('/makefriends', reqValidator.makeFriends, makeFriends)
21router.get('/quitfriends', cacheMiddleware.cache(false), quitFriends) 20router.get('/quitfriends', quitFriends)
22// Post because this is a secured request 21// Post because this is a secured request
23router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods) 22router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods)
24 23
diff --git a/server/controllers/api/v1/remoteVideos.js b/server/controllers/api/v1/remoteVideos.js
index 7da9f0105..cc4bc41e2 100644
--- a/server/controllers/api/v1/remoteVideos.js
+++ b/server/controllers/api/v1/remoteVideos.js
@@ -5,7 +5,6 @@ const map = require('lodash/map')
5 5
6const middleware = require('../../../middlewares') 6const middleware = require('../../../middlewares')
7const secureMiddleware = middleware.secure 7const secureMiddleware = middleware.secure
8const cacheMiddleware = middleware.cache
9const reqValidator = middleware.reqValidators.remote 8const reqValidator = middleware.reqValidators.remote
10const logger = require('../../../helpers/logger') 9const logger = require('../../../helpers/logger')
11const Videos = require('../../../models/videos') 10const Videos = require('../../../models/videos')
@@ -17,7 +16,6 @@ router.post('/add',
17 reqValidator.secureRequest, 16 reqValidator.secureRequest,
18 secureMiddleware.decryptBody, 17 secureMiddleware.decryptBody,
19 reqValidator.remoteVideosAdd, 18 reqValidator.remoteVideosAdd,
20 cacheMiddleware.cache(false),
21 addRemoteVideos 19 addRemoteVideos
22) 20)
23 21
@@ -25,7 +23,6 @@ router.post('/remove',
25 reqValidator.secureRequest, 23 reqValidator.secureRequest,
26 secureMiddleware.decryptBody, 24 secureMiddleware.decryptBody,
27 reqValidator.remoteVideosRemove, 25 reqValidator.remoteVideosRemove,
28 cacheMiddleware.cache(false),
29 removeRemoteVideo 26 removeRemoteVideo
30) 27)
31 28
diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js
index 0584d5cdf..54ff0d743 100644
--- a/server/controllers/api/v1/users.js
+++ b/server/controllers/api/v1/users.js
@@ -4,14 +4,12 @@ const config = require('config')
4const express = require('express') 4const express = require('express')
5const oAuth2 = require('../../../middlewares/oauth2') 5const oAuth2 = require('../../../middlewares/oauth2')
6 6
7const middleware = require('../../../middlewares')
8const cacheMiddleware = middleware.cache
9const Users = require('../../../models/users') 7const Users = require('../../../models/users')
10 8
11const router = express.Router() 9const router = express.Router()
12 10
13router.get('/client', cacheMiddleware.cache(false), getAngularClient) 11router.get('/client', getAngularClient)
14router.post('/token', cacheMiddleware.cache(false), oAuth2.token, success) 12router.post('/token', oAuth2.token, success)
15 13
16// --------------------------------------------------------------------------- 14// ---------------------------------------------------------------------------
17 15
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index c86a96a25..9891bf4c6 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -11,7 +11,6 @@ const logger = require('../../../helpers/logger')
11const friends = require('../../../lib/friends') 11const friends = require('../../../lib/friends')
12const middleware = require('../../../middlewares') 12const middleware = require('../../../middlewares')
13const oAuth2 = require('../../../middlewares/oauth2') 13const oAuth2 = require('../../../middlewares/oauth2')
14const cacheMiddleware = middleware.cache
15const reqValidator = middleware.reqValidators.videos 14const reqValidator = middleware.reqValidators.videos
16const utils = require('../../../helpers/utils') 15const utils = require('../../../helpers/utils')
17const Videos = require('../../../models/videos') // model 16const Videos = require('../../../models/videos') // model
@@ -42,11 +41,11 @@ const storage = multer.diskStorage({
42const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) 41const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
43const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) 42const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails'))
44 43
45router.get('/', cacheMiddleware.cache(false), listVideos) 44router.get('/', listVideos)
46router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) 45router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, addVideo)
47router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos) 46router.get('/:id', reqValidator.videosGet, getVideos)
48router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo) 47router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, removeVideo)
49router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos) 48router.get('/search/:name', reqValidator.videosSearch, searchVideos)
50 49
51// --------------------------------------------------------------------------- 50// ---------------------------------------------------------------------------
52 51
diff --git a/server/middlewares/cache.js b/server/middlewares/cache.js
deleted file mode 100644
index 1b621f6dc..000000000
--- a/server/middlewares/cache.js
+++ /dev/null
@@ -1,23 +0,0 @@
1'use strict'
2
3const cacheMiddleware = {
4 cache: cache
5}
6
7function cache (cache) {
8 return function (req, res, next) {
9 // If we want explicitly a cache
10 // Or if we don't specify if we want a cache or no and we are in production
11 if (cache === true || (cache !== false && process.env.NODE_ENV === 'production')) {
12 res.setHeader('Cache-Control', 'public')
13 } else {
14 res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
15 }
16
17 next()
18 }
19}
20
21// ---------------------------------------------------------------------------
22
23module.exports = cacheMiddleware
diff --git a/server/middlewares/index.js b/server/middlewares/index.js
index d85f6261c..a0b07705d 100644
--- a/server/middlewares/index.js
+++ b/server/middlewares/index.js
@@ -1,11 +1,9 @@
1'use strict' 1'use strict'
2 2
3const cacheMiddleware = require('./cache')
4const reqValidatorsMiddleware = require('./reqValidators') 3const reqValidatorsMiddleware = require('./reqValidators')
5const secureMiddleware = require('./secure') 4const secureMiddleware = require('./secure')
6 5
7const middlewares = { 6const middlewares = {
8 cache: cacheMiddleware,
9 reqValidators: reqValidatorsMiddleware, 7 reqValidators: reqValidatorsMiddleware,
10 secure: secureMiddleware 8 secure: secureMiddleware
11} 9}