-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (59 loc) · 1.58 KB
/
Copy pathindex.js
File metadata and controls
70 lines (59 loc) · 1.58 KB
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
/*
* Rest api for thoth
*
* @author Damiano Braga <damiano.braga@gmail.com>
*/
require('./environment')();
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var util = require('util');
// Dispatchers
var serversDispatcher = require('./dispatchers/servers_dispatcher');
var poolsDispatcher = require('./dispatchers/pools_dispatcher');
var listDispatcher = require('./dispatchers/list_dispatcher');
// Setup websocket for real time data flow
io.on('connection', function(socket){
socket.on('queryParams', function(queryParams) {
module.exports.io = io;
var realtimeDispatcher = require('./dispatchers/realtime_dispatcher');
realtimeDispatcher.pollRealTimeData(queryParams);
});
});
// Start node server
http.listen(process.env.PORT);
console.info('Server started at http://localhost:' + process.env.PORT);
/**
* Routes available
*/
var routeBase = [
'/api/%s/%s',
'/core/:core',
'/port/:port',
'/start/:start',
'/end/:end',
'/:information',
'/:attribute'
].join('');
/**
* Servers
*/
var serverRoute = util.format(routeBase, 'server', ':server');
app.get(serverRoute, function (req, res) {
serversDispatcher.dispatchServer(req, res)
});
app.get(serverRoute + '/:page', function (req, res) {
serversDispatcher.dispatchServer(req, res)
});
/**
* Pools
*/
app.get(util.format(routeBase, 'pool', ':pool'), function (req, res) {
poolsDispatcher.dispatchPool(req, res)
});
/**
* Info
*/
app.get('/api/list/:attribute', function (req, res) {
listDispatcher.dispatchList(req, res);
});