Faster block all routes in Express

I try

var _LOCK_ = true; // or load it from config

app.all('*', function(req,res,next){
   if(_LOCK_) return res.send(401);
   next();
});

// this place other routes
app.get(...);
app.post(...);

This works well. But I doubt whether all right?

app.use is more appropriate for a function that you want processed on every request. It will be slightly faster since it avoids having to match the route against the request URL.

var _LOCK_ = true; // or load it from config

app.use(function(req,res,next){
   if(_LOCK_) return res.send(401);
   next();
});
app.use(app.router); // your middleware function must be above the router