2013-07-17 24 views
0

這工作:express.static + middlware = 404

http://localhost:3000/private/test2.html 
app.use('/private',express.static(path.join(__dirname, 'private'))); 

但是當我加入中間件,該頁面無法找到。

var secure = function(req,res,next) { 
    console.log('in here' + req.url); 
    next(); 
} 
app.use('/private',secure,express.static(path.join(__dirname, 'private'))); 

隨着中間件的到位,我得到了404。我在這裏錯過了什麼?

回答

0

你應該中間件改成這樣:

app.use(secure); 
// use the middleware function 

app.use('/private',express.static(path.join(__dirname, 'private'))); 
// serve static files from private subfolder using 'private/' as matching prefix 
// static should be used at the end as it finishes the response. 
+0

謝謝,我是越來越混雜在一起app.get和app.use –

0

app.use只需要一個參數。你需要將它分成兩個app.use() s。

相關問題