mime中间件

mime中间件Demo,里面用到的有

1.path模块 //引入模块

var path=require('path');

2.extname方法 //获取文件的扩展名

var extname=path.extname(realPath)

var path=require('path');
    mime={
        "html": "text/html",
        "js": "text/javascript",
        "css": "text/css",
        "xml": "text/xml",
        "txt": "text/plain",
        "ico": "image/x-icon",
        "svg": "image/svg+xml",
        "gif": "image/gif",
        "png": "image/png",
        "jpg": "image/jpeg",
        "jpeg": "image/jpeg",
        "tiff": "image/tiff",
        "json": "application/json",
        "pdf": "application/pdf",
        "swf": "application/x-shockwave-flash",
        "wav": "audio/x-wav",
        "wma": "audio/x-ms-wma",
        "wmv": "video/x-ms-wmv"
    };

module.exports=function (realPath){
    var extname=path.extname(realPath),
        ext=extname?extname.slice(1):'unknown',
        contentType=mime[ext] ||'text/plain';

    return contentType;
};

  

posted @ 2015-06-18 14:26  Rain-Heart  阅读(187)  评论(0编辑  收藏  举报