/**
* Created by su on 2019/2/27.
*/
var http = require("http");
var url=require("url");
var server= http.createServer();
server.on("request",function(req,res){
//req.url:访问路径
//?后面部分是 query string
//console.log(req.url)
var urlStr=url.parse(req.url);
switch (urlStr.pathname){
case "/":
res.writeHead(200,{"content-type":"text/html;charset=utf-8"});
res.end("<h1>欢迎进入首页</h1>");
break;
case "/a":
res.writeHead(200,{"content-type":"text/html;charset=utf-8"});
res.end("<h1>欢迎进去a</h1>");
break;
case "/b":
res.writeHead(200,{"content-type":"text/html;charset=utf-8"});
res.end("<h1>欢迎进去b</h1>");
break;
default :
res.writeHead(404,{"content-type":"text/html;charset=utf-8"});
res.end("<h1>404</h1>");
break;
}
});
server.listen(8080,"localhost");