-
Notifications
You must be signed in to change notification settings - Fork 0
/
dd.js
46 lines (45 loc) · 969 Bytes
/
dd.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
42
43
44
45
46
var http = require("http");
var fs = require("fs");
var qs = require("querystring");
var util = require("util");
http.createServer(function(req,res){
var postData = "";
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;
}
}
if(req.method === "POST"){
switch(req.url){
case "/add.js":
req.on("data",function(chunck){
postData += chunck;
});
req.on("end",function(){
console.log(postData);
postData = qs.parse(postData);
res.end(util.inspect(postData));
})
break;
}
}
}).listen(3000);