-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.file.js
51 lines (43 loc) · 1.27 KB
/
http.file.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
47
48
49
50
51
var fs=require('fs');
var http=require('http');
var url=require('url');
http.createServer(function(request,response){
console.log("ServerRunning1");
fs.readFile('htmlPage.html', function(error,data){
response.writeHead(200,{'Content-Type':'text/html'})
response.end(data);
});
}).listen(52273, function(){
console.log("ServerRunning");
})
http.createServer(function(request,response){
var date=new Date();
console.log(date);
date.setDate(date.getDate()+7);
console.log(date+"7일 후 날짜");
response.writeHead(200,{'Content-Type':'text/html',
'Set-Cookie':['breakfast=toast;Expires='+date.toUTCString(),'dinner=chicken']
});
response.end('<h1>'+request.headers.cookie+'</h1>')
}).listen(52274, function(){
console.log("52274");
});
http.createServer(function(request,response){
var pathname=url.parse(request.url).pathname;
if(pathname=='/'){
fs.readFile('htmlPage.html',function(error,data){
response.writeHead(200,{
'Content-Type':'text/html'
});
response.end(data);
})
}else if(pathname=='/otherPage'){
fs.readFile('otherPage.html', function(error,data){
response.writeHead(200,{
'Content-Type':'text/html'
});
response.end(data);
})
}
}).listen(52275, function(){
})