-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (39 loc) · 887 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var http = require("http");
var fs = require("fs");
var app = http.createServer(function(req,res){
var postData = "";
console.log(req.method);
console.log(req.url);
if(req.method === "GET"){
switch(req.url){
case "/index.html":
fs.readFile("index.html",function(err,data){
if(err) throw err;
res.writeHeader(200,{"Content-Type":"text/html"});
res.write(data.toString());
res.end();
})
break;
case "/add.html":
fs.readFile("add.html",function(err,data){
if(err) throw err;
res.writeHeader(200,{"Content-Type":"text/html"});
res.write(data.toString());
res.end();
})
break;
}
}else if(req.method ==="POST"){
switch(req.url){
case "/add.js":
req.on("data",function(chunck){
postData +=chunck;
});
req.on("end",function(){
res.write(postData);
res.end();
})
break;
}
}
}).listen(3030);