我有一个关于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(像大多数静态资源一样)缓存在浏览器中,然后没有从服务器明确请求 –