相关疑难解决方法(0)

使用express.js的静态文件

我想将服务index.html/media子目录作为静态文件.索引文件应该在/index.html/URL处提供.

我有

web_server.use("/media", express.static(__dirname + '/media'));
web_server.use("/", express.static(__dirname));
Run Code Online (Sandbox Code Playgroud)

但第二行显然服务于整个__dirname,包括其中的所有文件(不只是index.htmlmedia),我不想要.

我也试过了

web_server.use("/", express.static(__dirname + '/index.html'));
Run Code Online (Sandbox Code Playgroud)

但访问基本URL /然后导致对web_server/index.html/index.html(双index.html组件)的请求,当然这会失败.

有任何想法吗?


顺便说一句,我可以在Express中找到关于这个主题的绝对文档(static()+它的参数)......令人沮丧.文档链接也是受欢迎的.

node.js express

195
推荐指数
7
解决办法
30万
查看次数

标签 统计

express ×1

node.js ×1