|
|
@ -27,20 +27,6 @@ module.exports = function (middleware) {
|
|
|
|
'^/language/.+',
|
|
|
|
'^/language/.+',
|
|
|
|
'^/uploads/system/site-logo.png'
|
|
|
|
'^/uploads/system/site-logo.png'
|
|
|
|
];
|
|
|
|
];
|
|
|
|
var render = function () {
|
|
|
|
|
|
|
|
res.status(503);
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
|
|
|
site_title: meta.config.title || 'NodeBB',
|
|
|
|
|
|
|
|
message: meta.config.maintenanceModeMessage
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!isApiRoute.test(url)) {
|
|
|
|
|
|
|
|
middleware.buildHeader(req, res, function () {
|
|
|
|
|
|
|
|
res.render('503', data);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
res.json(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var isAllowed = function (url) {
|
|
|
|
var isAllowed = function (url) {
|
|
|
|
for(var x = 0,numAllowed = allowedRoutes.length,route; x < numAllowed; x++) {
|
|
|
|
for(var x = 0,numAllowed = allowedRoutes.length,route; x < numAllowed; x++) {
|
|
|
@ -52,25 +38,28 @@ module.exports = function (middleware) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var isApiRoute = /^\/api/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isAllowed(url)) {
|
|
|
|
if (isAllowed(url)) {
|
|
|
|
return next();
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!req.user) {
|
|
|
|
user.isAdministrator(req.uid, function (err, isAdmin) {
|
|
|
|
return render();
|
|
|
|
if (err || isAdmin) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user.isAdministrator(req.user.uid, function (err, isAdmin) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return next(err);
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isAdmin) {
|
|
|
|
|
|
|
|
render();
|
|
|
|
res.status(503);
|
|
|
|
} else {
|
|
|
|
var data = {
|
|
|
|
next();
|
|
|
|
site_title: meta.config.title || 'NodeBB',
|
|
|
|
|
|
|
|
message: meta.config.maintenanceModeMessage
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res.locals.isAPI) {
|
|
|
|
|
|
|
|
return res.json(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
middleware.buildHeader(req, res, function () {
|
|
|
|
|
|
|
|
res.render('503', data);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|