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(); + }); + }); });