I want to serve index.html
and /media
subdirectory as static files. The index file should be served both at /index.html
and /
URLs.
I have
web_server.use("/media", express.static(__dirname + '/media'));
web_server.use("/", express.static(__dirname));
but the second line apparently serves the entire __dirname
, including all files in it (not just index.html
and media
), which I don't want.
I also tried
web_server.use("/", express.static(__dirname + '/index.html'));
but accessing the base URL /
then leads to a request to web_server/index.html/index.html
(double index.html
component), which of course fails.
Any ideas?
By the way, I could find absolutely no documentation in Express on this topic (static()
+ its params)... frustrating. A doc link is also welcome.
express.static()
is handled byserve-static
package middleware. you can find its docs at npmjs.com/package/serve-static or github.com/expressjs/serve-static. – Anm