From 874d0bf81bf767c689aef054edc40fc9adc592fa Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 27 Sep 2022 17:41:56 +0800 Subject: [PATCH] Made Content API caching configurable refs https://github.com/TryGhost/Toolbox/issues/411 - Having hardcoded cache control values in the codebase makes it impossible to experiment with new values without a version release. - Having all values configurable by default will allow for easier caching experiments and customizations on self-hosting instances. --- ghost/core/core/server/web/api/endpoints/content/app.js | 3 ++- ghost/core/core/shared/config/defaults.json | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ghost/core/core/server/web/api/endpoints/content/app.js b/ghost/core/core/server/web/api/endpoints/content/app.js index ce220f79af..7d8aa98b89 100644 --- a/ghost/core/core/server/web/api/endpoints/content/app.js +++ b/ghost/core/core/server/web/api/endpoints/content/app.js @@ -3,6 +3,7 @@ const boolParser = require('express-query-boolean'); const bodyParser = require('body-parser'); const express = require('../../../../../shared/express'); const sentry = require('../../../../../shared/sentry'); +const config = require('../../../../../shared/config'); const shared = require('../../../shared'); const routes = require('./routes'); const errorHandler = require('@tryghost/mw-error-handler'); @@ -22,7 +23,7 @@ module.exports = function setupApiApp() { // Content API should allow public caching apiApp.use(shared.middleware.cacheControl('public', { - maxAge: 0 + maxAge: config.get('caching:contentAPI:maxAge') })); // Routing diff --git a/ghost/core/core/shared/config/defaults.json b/ghost/core/core/shared/config/defaults.json index 02ac8f63ce..e13c9f9858 100644 --- a/ghost/core/core/shared/config/defaults.json +++ b/ghost/core/core/shared/config/defaults.json @@ -131,6 +131,9 @@ }, "cors": { "maxAge": 86400 + }, + "contentAPI": { + "maxAge": 0 } }, "imageOptimization": {