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
Post a Comment