forked from perezpaya/lolfire-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
116 lines (81 loc) · 3.22 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Global modules
global.async = require('async');
require(__dirname + '/mixpanel');
require(__dirname + '/connections');
//var lolrmtp = require('./lolrmtp/main').client;
var api = require(__dirname + '/api');
var express = require('express');
// Constructs modules
global.app = express();
var appRouter = require(__dirname + '/router');
// Middlewares
app.engine('ejs', require('ejs').__express);
app.set('views', __dirname + '/views');
app.use(express.compress());
app.use(express.staticCache());
app.use(express.static( __dirname + '/static'));
//app.use('icons', express.static( __dirname + '/icons'));
app.set('view engine', 'ejs');
app.use(function (req, res, next){
res.setHeader('Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Origin', '*');
next();
});
app.use(app.router); // Always the last middleware
// Full Regions Name
global.fullRegions = {
'euw': 'Europe West',
'na': 'North America',
'eune': 'Europe North & East'
//'ru': 'Russia'
};
// Checks if server is connected to that region
var regionChecker = function (req, res, next){
if(regions[req.params.region] && regions[req.params.region].connected){
next();
} else{
res.render('err.ejs');
}
};
var regionCheckerApi = function (req, res, next){
if(regions[req.params.region] && regions[req.params.region].connected){
next();
} else{
res.send({err: 'Region down, come back later'});
}
};
/*
AAA PPPPPP III
AA AA PP PP III
AA AA PP PP III
AAAAAAA PPPPPP III
AA AA PP III
AA AA PP III
HERE GOES THE API HANDLING AND CODE
*/
app.get('/api/v1/status', api.status);
app.get('/api/v1/:region/summoner/:name', regionCheckerApi, api.summoner, trackApiRequest);
app.get('/api/v1/:region/stats/:id', regionCheckerApi, api.stats, trackApiRequest);
app.get('/api/v1/:region/aggregatedstats/:id', regionCheckerApi, api.aggregatedStats, trackApiRequest);
app.get('/api/v1/:region/matches/:id', regionCheckerApi, api.matches, trackApiRequest);
app.get('/api/v1/:region/teams/:id', regionCheckerApi, api.teams, trackApiRequest);
app.get('/api/v1/:region/teamdata/:id', regionCheckerApi, api.teamInfo, trackApiRequest);
app.get('/api/v1/:region/active/:name', regionCheckerApi, api.activeMatch, trackApiRequest);
app.get('/api/v1/:region/summonerNames/:ids', regionCheckerApi, api.summonerNames, trackApiRequest);
app.get('/api/v1/:region/leagues/:id', regionCheckerApi, api.leagues, trackApiRequest);
// WEBAPP
app.get('/', appRouter.index);
app.get('/:region/summoner/:name', regionChecker, appRouter.summoner);
app.get('/:region/summoner/:name/ranked', regionChecker, appRouter.ranked);
app.get('/np', function (req, res){
res.render('np.ejs');
});
app.get('/thanks', function (req, res){
res.render('thx.ejs');
});
// This route goes in the last position, if any of the other routes have handle it, it will send 404 template
app.get('*', function (req, res){
res.render('404.ejs');
});
// Listens and creates the server
app.listen(80);