Skip to content

Commit

Permalink
Merge pull request TryGhost#5191 from jaswilli/issue-5155
Browse files Browse the repository at this point in the history
Allow admin app to run when active theme missing
  • Loading branch information
ErisDS committed Apr 26, 2015
2 parents 1e6f623 + 5cfb2e7 commit 18638d3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/server/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ function configHbsForContext(req, res, next) {
}

hbs.updateTemplateOptions({data: {blog: themeData}});
blogApp.set('views', path.join(config.paths.themePath, blogApp.get('activeTheme')));

if (config.paths.themePath && blogApp.get('activeTheme')) {
blogApp.set('views', path.join(config.paths.themePath, blogApp.get('activeTheme')));
}

// Pass 'secure' flag to the view engine
// so that templates can choose 'url' vs 'urlSSL'
Expand All @@ -110,13 +113,23 @@ function configHbsForContext(req, res, next) {
function updateActiveTheme(req, res, next) {
api.settings.read({context: {internal: true}, key: 'activeTheme'}).then(function (response) {
var activeTheme = response.settings[0];

// Check if the theme changed
if (activeTheme.value !== blogApp.get('activeTheme')) {
// Change theme
if (!config.paths.availableThemes.hasOwnProperty(activeTheme.value)) {
if (!res.isAdmin) {
// Throw an error if the theme is not available, but not on the admin UI
return errors.throwError('The currently active theme ' + activeTheme.value + ' is missing.');
} else {
// At this point the activated theme is not present and the current
// request is for the admin client. In order to allow the user access
// to the admin client we set an hbs instance on the app so that middleware
// processing can continue.
blogApp.engine('hbs', hbs.express3());
errors.logWarn('The currently active theme "' + activeTheme.value + '" is missing.');

return next();
}
} else {
activateTheme(activeTheme.value);
Expand Down

0 comments on commit 18638d3

Please sign in to comment.