javascript - Faster block all routes in Express -


i try

var _lock_ = true; // or load config  app.all('*', function(req,res,next){    if(_lock_) return res.send(401);    next(); });  // place other routes app.get(...); app.post(...); 

this works well. doubt whether right?

app.use more appropriate function want processed on every request. faster since avoids having match route against request url.

var _lock_ = true; // or load config  app.use(function(req,res,next){    if(_lock_) return res.send(401);    next(); }); app.use(app.router); // middleware function must above router 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -