我有一個關於app.get()
Express的問題。只要路徑末尾有.html
,函數似乎就不會被調用。在下面的代碼片段中,如果我嘗試去/random/example
,但是當我去/index.html
時,"test"
被寫入控制檯。那麼當我進入主頁時,如何讓它調用函數呢? (我以「/」作爲嘗試的路徑,它並不能工作。)Node.js express app.get()奇怪的行爲
app.use(express.static("public"))
app.get('/index.html',function(req,res){
console.log("test");
})
app.get('/random/example',function(req,res){
console.log("test");
})
您是否在某處定義了'app.static'? – GilZ
我已將您的問題中的堆棧片段轉換爲代碼塊。例如,Stack Snippets可以在代碼片段窗口中運行(例如,在瀏覽器上)。僅適用於服務器端的代碼不應該放在Stack Snippet中。 –
也許你的index.html(像大多數靜態資源一樣)緩存在瀏覽器中,然後沒有從服務器明確請求 –