diff --git a/src/middleware/maintenance.js b/src/middleware/maintenance.js new file mode 100644 index 0000000000..1df24a5f86 --- /dev/null +++ b/src/middleware/maintenance.js @@ -0,0 +1,77 @@ +'use strict'; + +var meta = require('../meta'); +var user = require('../user'); +var translator = require('../../public/src/modules/translator'); + + +module.exports = function(middleware) { + + middleware.maintenanceMode = function(req, res, next) { + console.log(req.path, meta.config.maintenanceMode) + if (parseInt(meta.config.maintenanceMode, 10) !== 1) { + return next(); + } + + var allowedRoutes = [ + '/login', + '/stylesheet.css', + '/nodebb.min.js', + '/vendor/fontawesome/fonts/fontawesome-webfont.woff', + '/src/(modules|client)/[\\w/]+.js', + '/templates/[\\w/]+.tpl', + '/api/login', + '/api/?', + '/language/.+', + '/uploads/system/site-logo.png' + ], + render = function() { + res.status(503); + + if (!isApiRoute.test(req.url)) { + middleware.buildHeader(req, res, function() { + res.render('maintenance', { + site_title: meta.config.title || 'NodeBB', + message: meta.config.maintenanceModeMessage + }); + }); + } else { + translator.translate('[[pages:maintenance.text, ' + meta.config.title + ']]', meta.config.defaultLang || 'en_GB', function(translated) { + res.json({ + error: translated + }); + }); + } + }, + isAllowed = function(url) { + for(var x=0,numAllowed=allowedRoutes.length,route;x