diff --git a/src/controllers/404.js b/src/controllers/404.js index fa64ab9f87..3843d6bace 100644 --- a/src/controllers/404.js +++ b/src/controllers/404.js @@ -55,7 +55,6 @@ exports.send404 = async function (req, res) { }); } - await middleware.inhibitCacheAsync(req, res); await middleware.buildHeaderAsync(req, res); await res.render('404', { path: validator.escape(path), diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index a0a5340c7c..c5f62658b0 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -420,6 +420,10 @@ helpers.formatApiResponse = async (statusCode, res, payload) => { } if (String(statusCode).startsWith('2')) { + if (res.req.loggedIn) { + res.set('cache-control', 'private'); + } + res.status(statusCode).json({ status: { code: 'ok', diff --git a/src/middleware/admin.js b/src/middleware/admin.js index d2511528ad..0f77f0121e 100644 --- a/src/middleware/admin.js +++ b/src/middleware/admin.js @@ -26,7 +26,6 @@ middleware.buildHeader = helpers.try(async (req, res, next) => { await require('./index').applyCSRFasync(req, res); } - res.set('cache-control', 'private'); res.locals.config = await controllers.api.loadConfig(req); next(); }); diff --git a/src/middleware/header.js b/src/middleware/header.js index 439e8bb7e8..f5722508b0 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -45,10 +45,6 @@ middleware.buildHeader = helpers.try(async (req, res, next) => { return res.redirect('/'); } - if (req.loggedIn) { - res.set('cache-control', 'private'); - } - res.locals.config = config; next(); }); diff --git a/src/middleware/headers.js b/src/middleware/headers.js index 99d817eaa5..dacfb62dec 100644 --- a/src/middleware/headers.js +++ b/src/middleware/headers.js @@ -3,7 +3,6 @@ const os = require('os'); const winston = require('winston'); const _ = require('lodash'); -const util = require('util'); const meta = require('../meta'); const languages = require('../languages'); @@ -109,13 +108,4 @@ module.exports = function (middleware) { return [defaultLang]; } } - - middleware.inhibitCache = (req, res, next) => { - if (req.loggedIn) { - res.set('cache-control', 'private'); - } - - next(); - }; - middleware.inhibitCacheAsync = util.promisify(middleware.inhibitCache); }; diff --git a/src/middleware/render.js b/src/middleware/render.js index 8555ee9314..cb8f82bc86 100644 --- a/src/middleware/render.js +++ b/src/middleware/render.js @@ -34,6 +34,10 @@ module.exports = function (middleware) { options.url = (req.baseUrl + req.path.replace(/^\/api/, '')); options.bodyClass = helpers.buildBodyClass(req, res, options); + if (req.loggedIn) { + res.set('cache-control', 'private'); + } + const buildResult = await plugins.hooks.fire(`filter:${template}.build`, { req: req, res: res, templateData: options }); if (res.headersSent) { return; diff --git a/src/routes/helpers.js b/src/routes/helpers.js index 5b680e13f2..8bcad07b22 100644 --- a/src/routes/helpers.js +++ b/src/routes/helpers.js @@ -18,7 +18,6 @@ function _handleArgs(middleware, middlewares, controller) { middleware.authenticateRequest, middleware.maintenanceMode, middleware.registrationComplete, - middleware.inhibitCache, middleware.pluginHooks, ...middlewares, ]; diff --git a/test/middleware.js b/test/middleware.js index 9c5cb71ca5..cdb2797360 100644 --- a/test/middleware.js +++ b/test/middleware.js @@ -100,7 +100,7 @@ describe('Middlewares', () => { }); }); - describe('.inhibitCache (cache-control header)', () => { + describe('cache-control header', () => { let uid; let jar;