|
@@ -2,7 +2,8 @@ var express = require('express')
|
|
|
, path = require('path')
|
|
|
, crypto = require('crypto')
|
|
|
, http = require('http')
|
|
|
- , winston = require('winston');
|
|
|
+ , winston = require('winston')
|
|
|
+ , fs = require('fs');
|
|
|
|
|
|
var app = express();
|
|
|
|
|
@@ -41,19 +42,36 @@ app.get('/play/:token/:time/:increment', function(req, res) {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+app.get('/logs', function(req, res) {
|
|
|
+ fs.readFile(__dirname + '/logs/games.log', function (err, data) {
|
|
|
+ if (err) {
|
|
|
+ res.redirect('/');
|
|
|
+ }
|
|
|
+ res.set('Content-Type', 'text/plain');
|
|
|
+ res.send(data);
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
var server = http.createServer(app).listen(app.get('port'), app.get('ipaddress'), function() {
|
|
|
console.log("Express server listening on port " + app.get('port'));
|
|
|
});
|
|
|
|
|
|
-winston.add(winston.transports.File, { filename: 'logs/games.log', handleExceptions: true, exitOnError: false });
|
|
|
+var games = {};
|
|
|
+var timer;
|
|
|
+
|
|
|
+
|
|
|
+ * Winston logger
|
|
|
+ */
|
|
|
+winston.add(winston.transports.File, {
|
|
|
+ filename: __dirname + '/logs/games.log',
|
|
|
+ handleExceptions: true,
|
|
|
+ exitOnError: false,
|
|
|
+ json: false
|
|
|
+});
|
|
|
winston.remove(winston.transports.Console);
|
|
|
winston.handleExceptions(new winston.transports.Console());
|
|
|
winston.exitOnError = false;
|
|
|
|
|
|
-
|
|
|
-var games = {};
|
|
|
-var timer;
|
|
|
-
|
|
|
|
|
|
* Sockets
|
|
|
*/
|
|
@@ -100,6 +118,7 @@ io.sockets.on('connection', function (socket) {
|
|
|
} else {
|
|
|
color = 'black';
|
|
|
}
|
|
|
+ winston.log('info', 'Number of currently running games', { '#': Object.keys(games).length });
|
|
|
} else {
|
|
|
var colors = ['black', 'white'];
|
|
|
|
|
@@ -122,8 +141,6 @@ io.sockets.on('connection', function (socket) {
|
|
|
socket.emit('joined', {
|
|
|
'color': color
|
|
|
});
|
|
|
-
|
|
|
- winston.log('info', 'Number of games', { '#': Object.keys(games).length });
|
|
|
});
|
|
|
|
|
|
socket.on('timer-white', function (data) {
|