/*引入需要的 module*/ var http=require("http"); var fs=require("fs"); var server=http.createServer(function(request,response){ if(request.method==="GET"){ switch(request.url){ case "/": case "/index.html": fs.readFile("index.html",function(err,data){ if(err){ console.log(err); throw err; } response.writeHeader(200,{"Content-Type":"text/html"}); response.write(data.toString()); response.end(); }); break; case "/add.html": fs.readFile("add.html",function(err,data){ if(err){ console.log(err); throw err; } response.writeHeader(200,{"Content-Type":"text/html"}); response.write(data.toString()); response.end(); }); break; case "/remove.html": fs.readFile("remove.html",function(err,data){ if(err){ console.log(err); throw err; } response.writeHeader(200,{"Content-Type":"text/html"}); response.write(data.toString()); response.end(); }); break; case "/edit.html": fs.readFile("edit.html",function(err,data){ if(err){ console.log(err); throw err; } response.writeHeader(200,{"Content-Type":"text/html"}); response.write(data.toString()); response.end(); }); break; case "/find.html": fs.readFile("find.html",function(err,data){ if(err){ console.log(err); throw err; } response.writeHeader(200,{"Content-Type":"text/html"}); response.write(data.toString()); response.end(); }); break; default : console.log("invalid request URL :"+request.url); fs.readFile("404.html",function(err,data){ if(err){ console.log(err); throw err; } response.writeHeader(404,{"Content-Type":"text/html"}); response.write(data.toString()); response.end(); }); } } }); server.listen(80);
时间: 2024-10-12 04:02:04