2013-07-17 4 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에는 하나의 매개 변수 만 사용됩니다. 2 개의 app.use()으로 분할해야합니다.

관련 문제