forked from ggary9424/taipei-burglary-pattern-2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequestHandlers.js
58 lines (54 loc) · 1.3 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
58
var exec = require("child_process").exec;
fs = require('fs');
function test(response) {
console.log("test: function");
fs.readFile('./index.html', function (err, html) {
if (err) {
response.writeHead(200, {'Content-Type': 'text/css'});
response.write('test 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('./loading.html', function (err, html) {
if(err){
response.writeHead(200, {'Content-Type': 'text/css'});
response.write('other 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('other 404 NOT FOUND');
response.end();
return false;
}
else{
//response.writeHead(200, {'Content-Type': 'text/css'});
response.write(data);
response.end();
return true;
}
});
}
exports.test = test;
exports.loading = loading;
exports.other = other;