码迷,mamicode.com
首页 > 其他好文 > 详细

mime中间件

时间:2015-06-18 15:18:47      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

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;
};

  

mime中间件

标签:

原文地址:http://www.cnblogs.com/rainheader/p/4585789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!