Express: Setting content-type based on path/file?

后端 未结 6 1970
闹比i
闹比i 2020-12-09 16:46

I know Express has the res.contentType() method, but how to set automatically content type based on path/file (including static content)?

6条回答
  •  遥遥无期
    2020-12-09 17:03

    Also, if you want to extend the mime-types that express(connect) knows about, you can do

    express.static.mime.define({'text/plain': ['md']});
    

    or

    connect.static.mime.define({'text/plain': ['md']});
    

    PS: the mime module is now located at https://github.com/broofa/node-mime

提交回复
热议问题