2017-02-14 52 views
1

我對NodeJS不是很熟悉,並開始使用它和Express。現在我得到以下內容:我想提供一個index.html文件,但在此之前做一些其他事情。但由於我使用的是app.use(express.static(__dirname + '/client/public'));,因此瀏覽器請求不會影響app.get("/")功能。我如何解決這個問題?快速靜態中間件自動服務index.html

app.use(express.static(__dirname + '/client/src/css')); 
app.use(express.static(__dirname + '/client/public')); 

app.get('/', function (req, res) { 
    console.log('###GET REQUEST received'); 
    console.log(req); 
    res.sendFile(__dirname + '/index.html'); 
}); 

預先感謝您!

回答

2

訂單事宜。在Express.static聲明之前放置app.get路由。

+0

非常感謝你,這麼容易,但沒有想到這一點! – patreu22