-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (30 loc) · 896 Bytes
/
index.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
var http = require('http');
var fs = require('fs');
var url = require('url');
var path = require('path');
http.createServer(function (req, res) {
var uri = url.parse(req.url).pathname;
console.log(uri);
ext = path.extname(uri);
if (ext == '') {
uri += '.html';
}
filePath = './public' + uri
console.log('Incoming request to ' + req.url);
console.log('Incoming request resolved to ' + filePath);
if (req.url === '/favicon.ico') {
return res.end();
}
fs.readFile(filePath, function (err, data) {
if (err) throw err;
console.log('ext is ' + ext);
if (ext == '.css') {
res.writeHead(200, {'Content-Type': 'text/css'});
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
}
res.write(data);
res.end();
});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');