【问题标题】:Express Send Files in Folder快速发送文件夹中的文件
【发布时间】:2021-11-28 11:21:56
【问题描述】:

我有一个服务器,里面有这样的文件:

- index.js
/client
 -index.html
 -about.html
 -signup.html
 -style.css

在 index.js 中,我有一个快速服务器。

  • 当用户转到/时,应该转到index.html
  • 当用户转到 /about.html 时,它应该转到 about.html 等
  • 当用户转到 /style.css 时,它应该转到 style.css 等。

我知道你可以这样做..

app.get('/', (req, res) => {
  res.sendFile(__dirname + '/client/index.html')
})

但我想让它自动发送正确的文件,而不必get每个文件夹。

我知道它与app.use 有关,但我不完全确定如何使用它。

【问题讨论】:

标签: javascript node.js express directory


【解决方案1】:

哎呀,没想到这么简单-

app.use('/', express.static('client'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 2014-11-23
    相关资源
    最近更新 更多