From 9b9e79ef271e18093ee1c97721179e9b4e4f4e5d Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 22 Sep 2014 20:31:57 -0400 Subject: [PATCH] re: #2099 --- src/middleware/middleware.js | 24 ++++++++++++++++++++++++ src/routes/index.js | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 555d5f8573..508abcab39 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -454,6 +454,30 @@ middleware.addExpiresHeaders = function(req, res, next) { next(); }; +middleware.maintenanceMode = function(req, res, next) { + var render = function() { + res.render('maintenance', { + site_title: meta.config.site_title || 'NodeBB' + }); + } + + if (meta.config.maintenanceMode === '1') { + if (!req.user) { + return render(); + } else { + user.isAdministrator(req.user.uid, function(err, isAdmin) { + if (!isAdmin) { + return render(); + } else { + return next(); + } + }); + } + } else { + return next(); + } +}; + module.exports = function(webserver) { app = webserver; middleware.admin = require('./admin')(webserver); diff --git a/src/routes/index.js b/src/routes/index.js index 253f00404a..98902835c2 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -165,6 +165,8 @@ module.exports = function(app, middleware) { pluginRouter.hotswapId = 'plugins'; authRouter.hotswapId = 'auth'; + app.use(middleware.maintenanceMode); + app.all(relativePath + '/api/?*', middleware.prepareAPI); app.all(relativePath + '/api/admin/*', middleware.admin.isAdmin, middleware.prepareAPI); app.all(relativePath + '/admin/?*', middleware.ensureLoggedIn, middleware.admin.isAdmin);