From 5dda52c924763a889e98b4cf97c588b34ef01812 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 13 May 2016 16:13:00 +0200 Subject: [PATCH] Remove the cache middleware --- server/controllers/api/v1/pods.js | 9 ++++----- server/controllers/api/v1/remoteVideos.js | 3 --- server/controllers/api/v1/users.js | 6 ++---- server/controllers/api/v1/videos.js | 11 +++++------ server/middlewares/cache.js | 23 ----------------------- server/middlewares/index.js | 2 -- 6 files changed, 11 insertions(+), 43 deletions(-) delete mode 100644 server/middlewares/cache.js 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') const logger = require('../../../helpers/logger') const friends = require('../../../lib/friends') const middleware = require('../../../middlewares') -const cacheMiddleware = middleware.cache const Pods = require('../../../models/pods') const reqValidator = middleware.reqValidators.pods const secureMiddleware = middleware.secure @@ -15,10 +14,10 @@ const Videos = require('../../../models/videos') const router = express.Router() -router.get('/', cacheMiddleware.cache(false), listPods) -router.post('/', reqValidator.podsAdd, cacheMiddleware.cache(false), addPods) -router.get('/makefriends', reqValidator.makeFriends, cacheMiddleware.cache(false), makeFriends) -router.get('/quitfriends', cacheMiddleware.cache(false), quitFriends) +router.get('/', listPods) +router.post('/', reqValidator.podsAdd, addPods) +router.get('/makefriends', reqValidator.makeFriends, makeFriends) +router.get('/quitfriends', quitFriends) // Post because this is a secured request router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods) 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') const middleware = require('../../../middlewares') const secureMiddleware = middleware.secure -const cacheMiddleware = middleware.cache const reqValidator = middleware.reqValidators.remote const logger = require('../../../helpers/logger') const Videos = require('../../../models/videos') @@ -17,7 +16,6 @@ router.post('/add', reqValidator.secureRequest, secureMiddleware.decryptBody, reqValidator.remoteVideosAdd, - cacheMiddleware.cache(false), addRemoteVideos ) @@ -25,7 +23,6 @@ router.post('/remove', reqValidator.secureRequest, secureMiddleware.decryptBody, reqValidator.remoteVideosRemove, - cacheMiddleware.cache(false), removeRemoteVideo ) 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') const express = require('express') const oAuth2 = require('../../../middlewares/oauth2') -const middleware = require('../../../middlewares') -const cacheMiddleware = middleware.cache const Users = require('../../../models/users') const router = express.Router() -router.get('/client', cacheMiddleware.cache(false), getAngularClient) -router.post('/token', cacheMiddleware.cache(false), oAuth2.token, success) +router.get('/client', getAngularClient) +router.post('/token', oAuth2.token, success) // --------------------------------------------------------------------------- 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') const friends = require('../../../lib/friends') const middleware = require('../../../middlewares') const oAuth2 = require('../../../middlewares/oauth2') -const cacheMiddleware = middleware.cache const reqValidator = middleware.reqValidators.videos const utils = require('../../../helpers/utils') const Videos = require('../../../models/videos') // model @@ -42,11 +41,11 @@ const storage = multer.diskStorage({ const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) const thumbnailsDir = path.join(__dirname, '..', '..', '..', '..', config.get('storage.thumbnails')) -router.get('/', cacheMiddleware.cache(false), listVideos) -router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) -router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos) -router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo) -router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos) +router.get('/', listVideos) +router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, addVideo) +router.get('/:id', reqValidator.videosGet, getVideos) +router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, removeVideo) +router.get('/search/:name', reqValidator.videosSearch, searchVideos) // --------------------------------------------------------------------------- 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 @@ -'use strict' - -const 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 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 @@ 'use strict' -const cacheMiddleware = require('./cache') const reqValidatorsMiddleware = require('./reqValidators') const secureMiddleware = require('./secure') const middlewares = { - cache: cacheMiddleware, reqValidators: reqValidatorsMiddleware, secure: secureMiddleware }