Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow maintenance mode to be set in config.js #7124

Merged
merged 1 commit into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/server/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ errors = {
function renderErrorInt(errorView) {
var stack = null;

if (statusCode !== 404 && process.env.NODE_ENV !== 'production' && err.stack) {
// Not Found and Maintenance Errors don't need a stack trace
if (statusCode !== 404 && statusCode !== 503 && process.env.NODE_ENV !== 'production' && err.stack) {
stack = parseStack(err.stack);
}

Expand Down
3 changes: 2 additions & 1 deletion core/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ function init(options) {
}).then(function () {
return versioning.getDatabaseVersion()
.then(function (currentVersion) {
var maintenanceState = config.maintenance.enabled || false;
config.maintenance.enabled = true;

migrations.update({
fromVersion: currentVersion,
toVersion: versioning.getNewestDatabaseVersion(),
forceMigration: process.env.FORCE_MIGRATION
}).then(function () {
config.maintenance.enabled = false;
config.maintenance.enabled = maintenanceState;
}).catch(function (err) {
errors.logErrorAndExit(err, err.context, err.help);
});
Expand Down
2 changes: 2 additions & 0 deletions core/server/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ setupMiddleware = function setupMiddleware(blogApp) {

// Mount admin express app to /ghost and set up routes
adminApp.use(redirectToSetup);
adminApp.use(maintenance);
adminApp.use(routes.admin());

blogApp.use('/ghost', adminApp);

// send 503 error page in case of maintenance
Expand Down
9 changes: 6 additions & 3 deletions core/server/middleware/maintenance.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
var config = require(__dirname + '/../config'),
errors = require(config.paths.corePath + '/server/errors');
var config = require('../config'),
i18n = require('../i18n'),
errors = require('../errors');

module.exports = function (req, res, next) {
if (config.maintenance.enabled) {
return next(new errors.Maintenance());
return next(new errors.Maintenance(
i18n.t('errors.general.maintenance')
));
}

next();
Expand Down
1 change: 1 addition & 0 deletions core/server/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
}
},
"general": {
"maintenance": "Ghost is currently undergoing maintenance, please wait a moment then retry.",
"moreInfo": "\nMore info: {info}",
"requiredOnFuture": "This will be required in future. Please see {link}"
},
Expand Down