Преглед на файлове

add maintenance and monitoring routes.

* `/world` to retrieve the current world state
* `/stats` for some basic statistics (# of users and pixls)
* `/reset` to reset the world state (not sure if forcing every client to
  clean the canvas is "right", maybe should not broadcast this?)
Lucas Stadler преди 12 години
родител
ревизия
b99be1407c
променени са 1 файла, в които са добавени 24 реда и са изтрити 1 реда
  1. 24 1
      js/pixl/server.js

+ 24 - 1
js/pixl/server.js

@ -5,6 +5,29 @@ var express = require('express');
5 5
var app = express();
6 6
app.use(express.static(__dirname + "/public"));
7 7
8
app.get('/stats', function(req, res) {
9
	var stats = {
10
		users: wss.clients.length,
11
		pixls: Object.keys(world).length
12
	};
13
	res.setHeader('Content-Type', 'text/plain');
14
	res.send(JSON.stringify(stats, null, "  "));
15
});
16
17
app.get('/world', function(req, res) {
18
	res.setHeader('Content-Type', 'text/plain');
19
	res.send(JSON.stringify(world));
20
});
21
22
app.get('/reset', function(req, res) {
23
	world = {};
24
	wss.clients.forEach(function(client) {
25
		client.send("{}");
26
	});
27
	res.setHeader('Content-Type', 'text/plain');
28
	res.send(JSON.stringify({status: "ok"}));
29
});
30
8 31
var server = http.createServer(app);
9 32
server.listen(8001);
10 33
@ -28,4 +51,4 @@ wss.on('connection', function(socket) {
28 51
			}
29 52
		});
30 53
	});
31
});
54
});