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

后端 未结 6 1982
闹比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:15

    Express uses Connect, Connect uses Mime, and Mime includes the files mime.types (with default mime types from Apache) and node.types (with some further types contributed by node community). You could just customize one of these files within your copy of mime in node_modules to add your required content type, or Mime also has an API that lets you specify additional content-types or .types files to load from your code.

    https://github.com/broofa/node-mime

提交回复
热议问题