-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
41 lines (37 loc) · 1.02 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
var static = require('node-static');
var _ = require("underscore");
var fileServer = new static.Server('./public');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
console.log(request.url);
if(request.url == '/bingo') {
printBingo(response);
response.end();
}
else {
fileServer.serve(request, response);
}
}).resume();
}).listen(8080, "0.0.0.0");
function printBingo(response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write('<!doctype html>\n<html>');
response.write('<h1>Star wars bingo</h1>');
response.write('<table border="1">');
var array = [];
for(var i=0;i<25;i++) {
array.push(i+1);
}
array = _.shuffle(array);
for(var i=0;i<array.length;i++) {
if(i%5 == 0) {
response.write('<tr>');
}
response.write('<td><img src="sw' + array[i] + '.jpeg"/></td>');
if(i%5 == 4) {
response.write('</tr>');
}
}
response.write('</table>');
response.write('</html>');
}