我已经使用 res.sendFile() 成功实现了提供静态文件,但是如果我添加一些查询字符串,它就不起作用。
例如,下面的代码工作得很好。
res.sendFile(path.join(__dirname, '../public', '/index.html'));
Run Code Online (Sandbox Code Playgroud)
但如果我这样做,它就会失败
res.sendFile(path.join(__dirname, '../public', '/index.html?id=' + req.params.id));
res.sendFile(path.join(__dirname, '../public', '/index.html?id=123'));
Run Code Online (Sandbox Code Playgroud)
然后我得到以下错误
ENOENT, stat '/Users/krishnandu/Documents/Project/public/index.html?id=123'
404
Error: ENOENT, stat '/Users/krishnandu/Documents/Project/public/index.html?id=123'
at Error (native)
Run Code Online (Sandbox Code Playgroud)