forked from trulia/thoth-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (41 loc) · 1.43 KB
/
index.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
47
48
49
50
51
52
/*
* Rest api for thoth
*
* @author Damiano Braga <[email protected]>
*/
require('./environment')();
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
// 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);
/**
* Routes available
*/
// Servers
app.get('/api/server/:server/core/:core/port/:port/start/:start/end/:end/:information/:attribute', function (req, res) {
serversDispatcher.dispatchServer(req, res)
});
app.get('/api/server/:server/core/:core/port/:port/start/:start/end/:end/:information/:attribute/:page', function (req, res) {
serversDispatcher.dispatchServer(req, res)
});
// Pools
app.get('/api/pool/:pool/core/:core/port/:port/start/:start/end/:end/:information/:attribute', function (req, res) {
poolsDispatcher.dispatchPool(req, res)
});
// Infos
app.get('/api/list/:attribute', function (req, res) {
listDispatcher.dispatchList(req, res);
});