-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (32 loc) · 853 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
/*!
* No Lights Biking Server
* Created by Korhan Akcura
*/
var http = require('http');
var fs = require('fs');
http.createServer(function (request, response) {
console.log('Page requested...');
var filePath = './public' + request.url;
if (filePath == './public/') {
// The default page
filePath = './public/index.html';
}
var contentType = request.headers['content-type'];
fs.readFile(filePath, function(error, content) {
if (error) {
if(error.code == 'ENOENT'){
response.writeHead(404);
response.end('<b>Not Found: '+error.code+'</b>');
}
else {
response.writeHead(500);
response.end('<b>Internal Server Error: '+error.code+'</b>');
}
}
else {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
}
});
}).listen(8081);
console.log('Server running...');