forked from wso2-attic/ux-font-wso2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (39 loc) · 1.29 KB
/
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
39
40
41
42
43
44
45
46
47
48
const http = require('http');
const fs = require('fs');
const cwd = 'docs';
module.exports = http.createServer(function (request, response) {
console.log('Received request for URL: ' + request.url);
var filePath = request.url.split("?").shift()
if (filePath == '/') {
filePath = cwd + '/index.html';
}
else {
filePath = cwd + filePath;
}
// var extname = path.extname(filePath);
fs.readFile(filePath, null, function(error, data){
if(error){
response.writeHead(404);
response.write('File not found.');
}
else{
// switch (extname) {
// case '.html':
// response.writeHead(200, {'Content-Type': 'text/html'});
// break;
// case '.js':
// response.writeHead(200, {'Content-Type': 'text/javascript'});
// break;
// case '.css':
// response.writeHead(200, {'Content-Type': 'text/css'});
// break;
// default:
// response.writeHead(200);
// break;
// }
response.writeHead(200);
response.write(data);
}
response.end();
});
});