-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
117 lines (98 loc) · 2.7 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var http = require('http'); // Import node.js core module
var fs = require("fs"); //Import file system module.
var port = 5000;
function handleRoutingError(res, err) {
res.writeHead(404);
res.write("Page not found");
console.log(err);
}
var server = http.createServer((req,res) => {
// Handle incoming requests
if (req.url == "/menses") {
// The web page for period data.
fs.readFile("./renders/mensesbubble.html", (err, file) => {
if (err) {
handleRoutingError(res, err);
} else {
// Set response header
res.writeHead(200, { 'Content-Type': 'text/html' });
// Set response content
res.write(file);
}
res.end();
});
} else if (req.url == "/data/menses.csv") {
// The raw period data.
fs.readFile("/home/saba/projects/personal-logs/dataentry/data/menses.csv", (err, file) => {
if (err) {
handleRoutingError(res, err);
} else {
res.writeHead(200, { 'Content-Type': 'text/csv' });
res.write(file);
}
res.end();
});
} else if (req.url == "/weight") {
// The web page for weight data.
fs.readFile("./renders/weight.html", (err, file) => {
if (err) {
handleRoutingError(res, err);
} else {
// Set response header
res.writeHead(200, { 'Content-Type': 'text/html' });
// Set response content
res.write(file);
}
res.end();
});
} else if (req.url == "/data/weights.csv") {
// The raw weight data.
fs.readFile("./data/weights.csv", (err, file) => {
if (err) {
handleRoutingError(err);
} else {
res.writeHead(200, { 'Content-Type': 'text/csv' });
res.write(file);
}
res.end();
});
} else if (req.url == "/routine") {
// The web page for routine data.
fs.readFile("./renders/fullroutine.html", (err, file) => {
if (err) {
handleRoutingError(err);
} else {
// Set response header
res.writeHead(200, { 'Content-Type': 'text/html' });
// Set response content
res.write(file);
}
res.end();
});
} else if (req.url == "/data/routine.json") {
// The raw routine data.
fs.readFile("./data/routine.json", (err, file) => {
if (err) {
handleRoutingError(err);
} else {
res.writeHead(200, { 'Content-Type': 'text/json'});
res.write(file);
}
res.end();
});
} else {
fs.readFile("./renders/homepage.html", (err, file) => {
if (err) {
handleRoutingError(err);
} else {
// Set response header
res.writeHead(200, { 'Content-Type': 'text/html' });
// Set response content
res.write(file);
}
res.end();
});
}
});
server.listen(port); // Listen for incoming requests
console.log("Server running at port "+port);