From cdc98dce150c25e863398de8279606d5be080904 Mon Sep 17 00:00:00 2001 From: JT Turner Date: Sat, 23 Jan 2016 12:34:11 -0800 Subject: [PATCH] Fixed ghost admin error when missing theme folder. closes #6368 - Add test to recreate the error in the static theme middleware. - Updated static theme middleware to not error if missing theme folder. --- core/server/middleware/static-theme.js | 12 +++++++---- .../test/unit/middleware/static-theme_spec.js | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/core/server/middleware/static-theme.js b/core/server/middleware/static-theme.js index 3b6654f8c7..bfa3a06959 100644 --- a/core/server/middleware/static-theme.js +++ b/core/server/middleware/static-theme.js @@ -11,10 +11,14 @@ function isBlackListedFileType(file) { } function forwardToExpressStatic(req, res, next) { - express.static( - path.join(config.paths.themePath, req.app.get('activeTheme')), - {maxAge: utils.ONE_YEAR_MS} - )(req, res, next); + if (!req.app.get('activeTheme')) { + next(); + } else { + express.static( + path.join(config.paths.themePath, req.app.get('activeTheme')), + {maxAge: utils.ONE_YEAR_MS} + )(req, res, next); + } } function staticTheme() { diff --git a/core/test/unit/middleware/static-theme_spec.js b/core/test/unit/middleware/static-theme_spec.js index 6a19d3df64..52b2a00733 100644 --- a/core/test/unit/middleware/static-theme_spec.js +++ b/core/test/unit/middleware/static-theme_spec.js @@ -65,4 +65,24 @@ describe('staticTheme', function () { done(); }); }); + + it('should not error if active theme is missing', function (done) { + var req = { + url: 'myvalidfile.css', + app: { + get: function () { return undefined; } + } + }, + activeThemeStub, + sandbox = sinon.sandbox.create(); + + activeThemeStub = sandbox.spy(req.app, 'get'); + + staticTheme(null)(req, null, function (reqArg, res, next2) { + /*jshint unused:false */ + sandbox.restore(); + next.called.should.be.false; + done(); + }); + }); });