2017-09-13 2 views
1

express.static가 루트 URL 요청을 처리 중입니다. 예 : 특급에서 https://example.com부터 https://example.com/dashboard까지 리디렉션하고 싶습니다. 아래의 사례를 확인하십시오. 먼저 작동하고 두 번째는 작동하지 않습니다. 나는 두 번째도 잘 작동 할 것으로 기대한다. 왜 그 사람이 누군지 압니까?express.static 처리 루트 URL 요청

사례 1 (작품)

app.get('/', (req, res, next) => { 
    res.redirect('/dashboard'); 
})  

app.use(express.static(path.join(__dirname, 'dist'))) 

app.get('/dashboard', (req, res, next) => { 
    //do stuff 
}) 

사례 2 (나를 위해 작동하지 않습니다) 파일 dist/index.html가 있다면 그 검색 할 때 찾는 것이 무엇 express.static() 때문에, 일어날 것

app.use(express.static(path.join(__dirname, 'dist'))) 

//request doesn't come here 
app.get('/', (req, res, next) => { 
    res.redirect('/dashboard') 
}) 

app.get('/dashboard', (req, res, next) => { 
    //do some stuff 
}) 
+0

그것이 – itsundefined

답변

3

디렉토리 (이 경우 /).

이 같은 그 동작을 해제 할 수 있습니다

app.use(express.static(path.join(__dirname, 'dist'), { index : false })) 

여기 문서화 :/DIST에 DIST를 변경 http://expressjs.com/en/4x/api.html#express.static

+0

좋은 답을 작동해야한다! @robertklep – turmuka

+0

와우 ... 매력처럼 작동합니다. @robertklep 감사합니다. – maxcc00

+0

원하지 않는 영향이있을 수 있다고 생각합니까? – maxcc00