-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
46 lines (40 loc) · 1.16 KB
/
routes.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
var fs = require('fs');
module.exports = function(path, response) {
var filename = false;
var filetype = "html";
switch(path) {
case '/':
filename = "index.html";
break;
case "/game":
filename = "game.html";
break;
case "/game.js":
filename = "game.js";
filetype = "javascript";
break;
case "/socket.io":
filename = "../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js";
filetype = "javascript";
break;
case "/favicon.ico":
default:
filename = false;
break;
}
if(filename) {
console.log("Routing "+path);
response.writeHead('200', {"Content-Type": "text/"+filetype});
fs.createReadStream("public/"+filename)
.on('end', function() {
console.log('end stream');
response.end();
})
.pipe(response);
}
else {
response.writeHead('404', {"Content-Type": "text/html"});
response.end();
}
return;
}