2013-07-17 45 views
0

所有路由我尝试更快块快递

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(...); 

这种运作良好。但我怀疑是否所有的权利?

+0

它完成这项工作。 – moka

回答

2

app.use更适合您希望在每个请求上处理的函数。它会稍微快一点,因为它避免了必须匹配请求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