-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (41 loc) · 973 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
42
43
44
45
46
47
48
var http=require('http');
var path=require('path');
var url=require('url');
var fs=require('fs');
/*
var server=http.createServer(function(req,res){
//res.write('nodejs');
//res.end();
if(req.url == '/index.html')
fs.readFile('./index.html',function(err,data){
res.end(data);
});
});
server.listen(8080);
var xhr= new XMLHttpRequest();
xhr.open('GET','index.html',true);
xhr.onreadystatechange=function(){
if(xhr.readyState == 4 && xhr.status == 200){
body.innerHTML=xhr.responseText;
}
}
xhr.send();*/
console.log(path.normalize('a/../b////c/d/'));
var server=http.createServer(err,function(req,res){
var root=path.resolve('.');
var pathname=path.parse(req.url);
var fildPath=path.join(root,pathname);
fs.stat(fildPath,function(err,stats){
if(!err && fildPath.isFile()){
res.writeHead(200);
fs.readFile(fildPath,function(err,data){
if(err){
throw err;
}else{
res.end(data);
}
})
}
})
});
server.listen(8686);