• app.js


    var port = 8080;
    var url  = require("url"),
        fs=require("fs"),
        http=require("http"),
        path = require("path");
    http.createServer(function (req, res) {
        var pathname=__dirname+url.parse(req.url).pathname;
        if (path.extname(pathname)=="") {
            pathname+="/";
        }
        if (pathname.charAt(pathname.length-1)=="/"){
            pathname+="popup.html";
        }
    
        fs.exists(pathname,function(exists){
            if(exists){
                switch(path.extname(pathname)){
                    case ".html":
                        res.writeHead(200, {"Content-Type": "text/html"});
                        break;
                    case ".js":
                        res.writeHead(200, {"Content-Type": "text/javascript"});
                        break;
                    case ".css":
                        res.writeHead(200, {"Content-Type": "text/css"});
                        break;
                    case ".gif":
                        res.writeHead(200, {"Content-Type": "image/gif"});
                        break;
                    case ".jpg":
                        res.writeHead(200, {"Content-Type": "image/jpeg"});
                        break;
                    case ".png":
                        res.writeHead(200, {"Content-Type": "image/png"});
                        break;
                    default:
                        res.writeHead(200, {"Content-Type": "application/octet-stream"});
                }
    
                fs.readFile(pathname,function (err,data){
                    res.end(data);
                });
            } else {
                res.writeHead(404, {"Content-Type": "text/html"});
                res.end("<h1>404 Not Found</h1>");
            }
        });
    }).listen(port);
    console.log("Server running at port "+port);
    钟声敲响了日落
  • 相关阅读:
    oracle触发器
    oracle存储函数
    ****Java程序调用存储过程****
    oracle储存过程--存储过程
    oracle储存过程--游标
    oracle存储过程--流程控制(条件判断和循环遍历)
    InterviewProblems
    RandomAccessFile浅析
    JSP基础——关于中文乱码问题
    基础数据结构——单链表
  • 原文地址:https://www.cnblogs.com/SATinnovation/p/7061109.html
Copyright © 2020-2023  润新知