Skip to content

Commit

Permalink
Fixed ghost admin error when missing theme folder.
Browse files Browse the repository at this point in the history
closes #6368
- Add test to recreate the error in the static theme middleware.
- Updated static theme middleware to not error if missing theme folder.
  • Loading branch information
jtwebman committed Jan 23, 2016
1 parent 57ae36a commit cdc98dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/server/middleware/static-theme.js
Expand Up @@ -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() {
Expand Down
20 changes: 20 additions & 0 deletions core/test/unit/middleware/static-theme_spec.js
Expand Up @@ -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();
});
});
});

0 comments on commit cdc98dc

Please sign in to comment.