明確地說,當我使用路由中間件時,可以追加到請求對象嗎?或者這是一種不好的模式?備擇方案?謝謝。可安全地追加到req參數?
app.get('/', getLayout, function(req, res){
if(req.layout == 'simple') ...render simple layout...
else ...render full layout...
});
其中
getLayout = function(req, res, next){
req.layout = (req.params.blah == 'blah') ? 'layout_simple' : 'layout_full';
next();
}
謝謝,當他們使用它時一定錯過了 – Mike 2012-02-19 21:53:50
沒問題,我也是最佳實踐的奴隸:) – 2012-02-19 22:02:16