Remove the cache middleware

This commit is contained in:
Chocobozzz 2016-05-13 16:13:00 +02:00
parent 788a7e0202
commit 5dda52c924
6 changed files with 11 additions and 43 deletions

View File

@ -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)

View File

@ -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
)

View File

@ -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)
// ---------------------------------------------------------------------------

View File

@ -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)
// ---------------------------------------------------------------------------

View File

@ -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

View File

@ -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
}