-
Notifications
You must be signed in to change notification settings - Fork 0
/
webserver.js
48 lines (38 loc) · 900 Bytes
/
webserver.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'),
url = require('url'),
fs = require('fs'),
server
server = http.createServer(function(req, res){
var path = url.parse(req.url).pathname;
switch(path){
case '/test':
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('It Works!\n');
res.end();
break;
case '/':
fs.readFile(__dirname + '/index.html', function(err, data){
if(err) return send404(res);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data, 'utf8');
res.end();
});
break;
case '/twitter':
fs.readFile(__dirname + '/twitter.html', function(err, data){
if(err) return send404(res);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data, 'utf8');
res.end();
});
break;
default: send404(res);
}
}),
send404 = function(res){
res.writeHead(404);
res.write('404');
res.end();
};
server.listen(8080);
//});