-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequestHandlers.js
57 lines (53 loc) · 1.25 KB
/
requestHandlers.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
49
50
51
52
53
54
55
56
57
var exec = require("child_process").exec;
var fs = require('fs');
function index(response) {
console.log("test: function");
fs.readFile('web/html/index.html', function(err, html) {
if (err) {
response.writeHead(200, {'Content-Type': 'text/css'});
response.write('404 NOT FOUND');
response.end();
throw err;
}
else {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}
});
}
function loading(response) {
console.log("loading");
fs.readFile('web/html/loading.html', function(err, html) {
if (err) {
response.writeHead(200, {'Content-Type': 'text/css'});
response.write('404 NOT FOUND');
response.end();
return false;
}
else {
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(html);
return true;
}
});
}
function other(response, pathname) {
console.log("other: "+pathname);
fs.readFile('.'+pathname, function(err, data) {
if (err) {
response.writeHead(200, {'Content-Type': 'text/css'});
response.write('404 NOT FOUND');
response.end();
return false;
}
else {
response.write(data);
response.end();
return true;
}
});
}
exports.index = index;
exports.loading = loading;
exports.other = other;