当前位置: 首页 > 工具软件 > fly-crm > 使用案例 >

js学习总结----crm客户管理系统之node创建服务发布项目

西门凯康
2023-12-01

server.js文件代码如下

var http = require('http'),
    url = require('url'),
    fs = require('fs');
var server  = http.createServer(function(req,res){
    var urlObj = url.parse(req.url,true),
        pathname = urlObj.pathname,
        query = urlObj.query;
    //静态资源文件请求的处理
    var reg = /\.(HTML|CSS|JS|ICO)/i;
    if(reg.test(pathname)){
        var suffix = reg.exec(pathname)[1].toUpperCase();
        var suffixMIME = "text/html";
        switch(suffix){
            case "CSS":
                suffixMIME = "text/css"
                break;
            case "JS":
                suffixMIME = "text/javascript"
                break;
        }
        try{
            var conFile = fs.readFileSync("."+pathname,'utf-8');
            res.writeHead(200,{'content-type':suffixMIME+";charset=utf-8"});
            res.end(conFile);
        }catch(e){
            res.writeHead(404,{'content-type':"text/plain;charset=utf-8"});
            res.end("file is not found~");
        }
    }

})
server.listen(80,function(){
    console.log("server is success,listening on 80 port")
})

 

转载于:https://www.cnblogs.com/diasa-fly/p/7273575.html

 类似资料: