- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
35 lines (29 loc) · 879 Bytes
/
Copy pathserver.js
File metadata and controls
35 lines (29 loc) · 879 Bytes
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
'use strict';
varhttp=require('http'),
path=require('path'),
fs=require('fs');
http.createServer(function(req,res){
vartype={
'.html': 'text/html',
'.css': 'text/css',
'.js': 'text/javascript'
};
if(req.method.toLowerCase()==='get'){
varfile=path.join(__dirname,req.url==='/' ? '/index.html' : req.url);
fs.readFile(file,function(err,body){
if(err){
res.writeHead(404);
res.end();
return;
}
res.writeHead(200,{
'Content-Length': body.length,
'content-type': type[path.extname(file)]||'text/plain'
});
res.end(body);
});
return;
}
res.writeHead(404);
res.end();
}).listen(3000);