/
nope.js
32 lines (30 loc) · 952 Bytes
/
nope.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
var http = require('http');
var fs = require('fs');
var readHtml = function (fileName, res) {
fs.readFile(__dirname + '\\' + fileName, 'utf8',
function (err, data) {
if (err) {
// Handle exception...
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(data);
}
});
};
var server = http.createServer(function (req, res) {
switch (req.url) {
case '/about.html':
readHtml('about.html', res);
break;
case '/index.html':
case '/':
readHtml('index.html', res);
break;
default:
res.writeHead(404, {'Content-Type': 'text/html'});
res.end('<h1>404 - Page not found!</h1><p>What were you even trying to do...?</p>');
break;
}
});
server.listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');