Skip to content

Commit d6bdb9b

Browse files
ErisDSgeekhuyang
authored andcommitted
Allow maintenance mode to be set in config.js (TryGhost#7124)
refs TryGhost#6976, TryGhost#7019, TryGhost#7125 - Ensure maintenance mode flag is set back to what is in config.js rather than defaulted to false on boot - Remove stack trace from 503 errors - Add error message to 503 error - Ensure error page is rendered for Ghost-Admin on reload with 503
1 parent e7a6881 commit d6bdb9b

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

core/server/errors/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ errors = {
324324
function renderErrorInt(errorView) {
325325
var stack = null;
326326

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

core/server/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ function init(options) {
6969
}).then(function () {
7070
return versioning.getDatabaseVersion()
7171
.then(function (currentVersion) {
72+
var maintenanceState = config.maintenance.enabled || false;
7273
config.maintenance.enabled = true;
7374

7475
migrations.update({
7576
fromVersion: currentVersion,
7677
toVersion: versioning.getNewestDatabaseVersion(),
7778
forceMigration: process.env.FORCE_MIGRATION
7879
}).then(function () {
79-
config.maintenance.enabled = false;
80+
config.maintenance.enabled = maintenanceState;
8081
}).catch(function (err) {
8182
errors.logErrorAndExit(err, err.context, err.help);
8283
});

core/server/middleware/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ setupMiddleware = function setupMiddleware(blogApp) {
197197

198198
// Mount admin express app to /ghost and set up routes
199199
adminApp.use(redirectToSetup);
200+
adminApp.use(maintenance);
200201
adminApp.use(routes.admin());
202+
201203
blogApp.use('/ghost', adminApp);
202204

203205
// send 503 error page in case of maintenance

core/server/middleware/maintenance.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
var config = require(__dirname + '/../config'),
2-
errors = require(config.paths.corePath + '/server/errors');
1+
var config = require('../config'),
2+
i18n = require('../i18n'),
3+
errors = require('../errors');
34

45
module.exports = function (req, res, next) {
56
if (config.maintenance.enabled) {
6-
return next(new errors.Maintenance());
7+
return next(new errors.Maintenance(
8+
i18n.t('errors.general.maintenance')
9+
));
710
}
811

912
next();

core/server/translations/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
}
171171
},
172172
"general": {
173+
"maintenance": "Ghost is currently undergoing maintenance, please wait a moment then retry.",
173174
"moreInfo": "\nMore info: {info}",
174175
"requiredOnFuture": "This will be required in future. Please see {link}"
175176
},

0 commit comments

Comments
 (0)