小编Kri*_*kar的帖子

使用查询字符串表示 res.sendFile()

我已经使用 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)

html static node.js express

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

express ×1

html ×1

node.js ×1

static ×1