You can create middleware that you can use for the routes you want to block:
var block = false;
var BlockingMiddleware = function(req, res, next) {
if (block === true)
return res.send(503);
next();
};
app.get('/registration', BlockingMiddleware, function(req, res) {
...
});
This is a simple example, obviously.
EDIT: a more complex example:
var Blocker = function() {
this.blocked = false;
};
Blocker.prototype.enableBlock = function() {
this.blocked = true;
};
Blocker.prototype.disableBlock = function() {
this.blocked = false;
};
Blocker.prototype.isBlocked = function() {
return this.blocked === true;
};
Blocker.prototype.middleware = function() {
var self = this;
return function(req, res, next) {
if (self.isBlocked())
return res.send(503);
next();
}
};
var blocker = new Blocker();
var BlockingMiddleware = blocker.middleware();
app.get('/registration', BlockingMiddleware, function(req, res) {
...
});
blocker.enableBlock();
blocker.disableBlock();
( , , "" Blocker, , , )