Setting up two different static directories in node.js Express framework

后端 未结 6 707
北恋
北恋 2020-11-30 22:21

Is it possible? I would like to set up two different directories to serve static files. Let\'s say /public and /mnt

6条回答
  •  佛祖请我去吃肉
    2020-11-30 22:37

    You can also "merge" directories into a single visible directory

    Directory Structure

    • /static
    • /alternate_static

    Code

    app.use("/static", express.static(__dirname + "/static"));
    app.use("/static", express.static(__dirname + "/alternate_static"));
    

    Both static and alternate_static will be served as if they were in the same directory. Watch out for filename clobbers, though.

提交回复
热议问题