我想将服务index.html和/media子目录作为静态文件提供。索引文件应同时在/index.html和/URL处提供。
我有
web_server.use("/media", express.static(__dirname + '/media'));
web_server.use("/", express.static(__dirname));
但第二行显然可以处理整个__dirname,包括其中的所有文件(不只是index.htmland media),我不希望这样。
我也试过
web_server.use("/", express.static(__dirname + '/index.html'));
但是访问基本URL /会导致对web_server/index.html/index.html(双重index.html组件)的请求,这当然会失败。
有任何想法吗?
顺便说一下,我在Express中找不到关于此主题的文档(static()+它的参数)...令人沮丧。也欢迎使用doc链接。
express.static()由serve-static包中间件处理。您可以在npmjs.com/package/serve-static或github.com/expressjs/serve-static中找到其文档。