2013-07-17 47 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