diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-13 16:13:00 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-13 16:13:00 +0200 |
commit | 5dda52c924763a889e98b4cf97c588b34ef01812 (patch) | |
tree | 0616e61d825dbfee6e0183555e47cdb7b1d7f472 /server | |
parent | 788a7e02029efae7c44bc4ec608493f67dac291a (diff) | |
download | PeerTube-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.js | 9 | ||||
-rw-r--r-- | server/controllers/api/v1/remoteVideos.js | 3 | ||||
-rw-r--r-- | server/controllers/api/v1/users.js | 6 | ||||
-rw-r--r-- | server/controllers/api/v1/videos.js | 11 | ||||
-rw-r--r-- | server/middlewares/cache.js | 23 | ||||
-rw-r--r-- | server/middlewares/index.js | 2 |
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') | |||
5 | const logger = require('../../../helpers/logger') | 5 | const logger = require('../../../helpers/logger') |
6 | const friends = require('../../../lib/friends') | 6 | const friends = require('../../../lib/friends') |
7 | const middleware = require('../../../middlewares') | 7 | const middleware = require('../../../middlewares') |
8 | const cacheMiddleware = middleware.cache | ||
9 | const Pods = require('../../../models/pods') | 8 | const Pods = require('../../../models/pods') |
10 | const reqValidator = middleware.reqValidators.pods | 9 | const reqValidator = middleware.reqValidators.pods |
11 | const secureMiddleware = middleware.secure | 10 | const secureMiddleware = middleware.secure |
@@ -15,10 +14,10 @@ const Videos = require('../../../models/videos') | |||
15 | 14 | ||
16 | const router = express.Router() | 15 | const router = express.Router() |
17 | 16 | ||
18 | router.get('/', cacheMiddleware.cache(false), listPods) | 17 | router.get('/', listPods) |
19 | router.post('/', reqValidator.podsAdd, cacheMiddleware.cache(false), addPods) | 18 | router.post('/', reqValidator.podsAdd, addPods) |
20 | router.get('/makefriends', reqValidator.makeFriends, cacheMiddleware.cache(false), makeFriends) | 19 | router.get('/makefriends', reqValidator.makeFriends, makeFriends) |
21 | router.get('/quitfriends', cacheMiddleware.cache(false), quitFriends) | 20 | router.get('/quitfriends', quitFriends) |
22 | // Post because this is a secured request | 21 | // Post because this is a secured request |
23 | router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods) | 22 | router.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 | ||
6 | const middleware = require('../../../middlewares') | 6 | const middleware = require('../../../middlewares') |
7 | const secureMiddleware = middleware.secure | 7 | const secureMiddleware = middleware.secure |
8 | const cacheMiddleware = middleware.cache | ||
9 | const reqValidator = middleware.reqValidators.remote | 8 | const reqValidator = middleware.reqValidators.remote |
10 | const logger = require('../../../helpers/logger') | 9 | const logger = require('../../../helpers/logger') |
11 | const Videos = require('../../../models/videos') | 10 | const 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') | |||
4 | const express = require('express') | 4 | const express = require('express') |
5 | const oAuth2 = require('../../../middlewares/oauth2') | 5 | const oAuth2 = require('../../../middlewares/oauth2') |
6 | 6 | ||
7 | const middleware = require('../../../middlewares') | ||
8 | const cacheMiddleware = middleware.cache | ||
9 | const Users = require('../../../models/users') | 7 | const Users = require('../../../models/users') |
10 | 8 | ||
11 | const router = express.Router() | 9 | const router = express.Router() |
12 | 10 | ||
13 | router.get('/client', cacheMiddleware.cache(false), getAngularClient) | 11 | router.get('/client', getAngularClient) |
14 | router.post('/token', cacheMiddleware.cache(false), oAuth2.token, success) | 12 | router.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') | |||
11 | const friends = require('../../../lib/friends') | 11 | const friends = require('../../../lib/friends') |
12 | const middleware = require('../../../middlewares') | 12 | const middleware = require('../../../middlewares') |
13 | const oAuth2 = require('../../../middlewares/oauth2') | 13 | const oAuth2 = require('../../../middlewares/oauth2') |
14 | const cacheMiddleware = middleware.cache | ||
15 | const reqValidator = middleware.reqValidators.videos | 14 | const reqValidator = middleware.reqValidators.videos |
16 | const utils = require('../../../helpers/utils') | 15 | const utils = require('../../../helpers/utils') |
17 | const Videos = require('../../../models/videos') // model | 16 | const Videos = require('../../../models/videos') // model |
@@ -42,11 +41,11 @@ const storage = multer.diskStorage({ | |||
42 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) | 41 | const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) |
43 | const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) | 42 | const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) |
44 | 43 | ||
45 | router.get('/', cacheMiddleware.cache(false), listVideos) | 44 | router.get('/', listVideos) |
46 | router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) | 45 | router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, addVideo) |
47 | router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos) | 46 | router.get('/:id', reqValidator.videosGet, getVideos) |
48 | router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo) | 47 | router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, removeVideo) |
49 | router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos) | 48 | router.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 | |||
3 | const cacheMiddleware = { | ||
4 | cache: cache | ||
5 | } | ||
6 | |||
7 | function 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 | |||
23 | module.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 | ||
3 | const cacheMiddleware = require('./cache') | ||
4 | const reqValidatorsMiddleware = require('./reqValidators') | 3 | const reqValidatorsMiddleware = require('./reqValidators') |
5 | const secureMiddleware = require('./secure') | 4 | const secureMiddleware = require('./secure') |
6 | 5 | ||
7 | const middlewares = { | 6 | const middlewares = { |
8 | cache: cacheMiddleware, | ||
9 | reqValidators: reqValidatorsMiddleware, | 7 | reqValidators: reqValidatorsMiddleware, |
10 | secure: secureMiddleware | 8 | secure: secureMiddleware |
11 | } | 9 | } |