Skip to content

Commit

Permalink
馃帹 fix admin and theme caching issues (#8058)
Browse files Browse the repository at this point in the history
refs #7812, closes #7958

- fixes boolean logic wrt to theme cache value from config
- disable cache for admin assets in development
- only add asset hash in production
  • Loading branch information
acburdine authored and kirrg001 committed Mar 2, 2017
1 parent 75ba25d commit 144544e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions core/server/admin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var debug = require('debug')('ghost:admin'),

module.exports = function setupAdminApp() {
debug('Admin setup start');
var adminApp = express();
var adminApp = express(),
configMaxAge;

// First determine whether we're serving admin or theme content
// @TODO finish refactoring this away.
Expand All @@ -36,9 +37,10 @@ module.exports = function setupAdminApp() {

// Admin assets
// @TODO ensure this gets a local 404 error handler
configMaxAge = config.get('caching:admin:maxAge');
adminApp.use('/assets', serveStatic(
config.get('paths').clientAssets,
{maxAge: utils.ONE_YEAR_MS, fallthrough: false}
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : utils.ONE_YEAR_MS, fallthrough: false}
));

// Service Worker for offline support
Expand Down
3 changes: 3 additions & 0 deletions core/server/config/env/config.development.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"caching": {
"theme": {
"maxAge": 0
},
"admin": {
"maxAge": 0
}
}
}
4 changes: 3 additions & 1 deletion core/server/middleware/static-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ function forwardToExpressStatic(req, res, next) {
if (!req.app.get('activeTheme')) {
next();
} else {
var configMaxAge = config.get('caching:theme:maxAge');

express.static(path.join(config.getContentPath('themes'), req.app.get('activeTheme')),
{maxAge: config.get('caching:theme:maxAge') || utils.ONE_YEAR_MS}
{maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : utils.ONE_YEAR_MS}
)(req, res, next);
}
}
Expand Down

0 comments on commit 144544e

Please sign in to comment.