Julian Lam 10 years ago
parent bfdc32a9c3
commit 9b9e79ef27

@ -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);

@ -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);

Loading…
Cancel
Save