从/服务静态文件

时间:2017-11-19 02:09:17

标签: node.js express

如果我定义

app.use('/*', express.static(path.join(__dirname, '../pub/index.html')));

然后看来我需要在我的网址之后提供至少一个字符才能获得index.html。 如果我用/定义路由,我会在浏览器中获得404。

如何仅使用/提供默认文件?

1 个答案:

答案 0 :(得分:0)

您可以使用serve-static

app.use(serveStatic(path.join(__dirname, '../pub'), {'index' ['index.html']}));

它应该提供 index.html ,它位于 ../ pub 中,如果您调用例如localhost:3000

相关问题