-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
173 lines (170 loc) · 5.77 KB
/
Copy pathapp.js
File metadata and controls
173 lines (170 loc) · 5.77 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// READ THIS
// https://developer.riotgames.com/getting-started.html
const riot = require('./config/keys').riotGamesApi;
const express = require('express');
const app = express();
const path = require('path');
const fetch = require('node-fetch');
const PORT = process.env.PORT || 3702;
const api_path = 'https://na1.api.riotgames.com/lol';
// This logic is used for Heroku deployment
// to make sure we don't have to "run build" before pushing to Heroku
// if (process.env.NODE_ENV === 'production') {
app.use(express.static('dist'));
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, 'dist', 'index.html'));
})
// }
/* ---------------------------------------------
// FIND A PRO PLAYER BY THEIR SUMMONER NAME
--------------------------------------------- */
app.get('/player/:name', (req, res) => {
const summonerName = req.params.name;
fetch(`${api_path}/summoner/v4/summoners/by-name/${summonerName}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
// const results = body.json();
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "player" ERROR, GABE! -----');
console.log(err);
});
});
/* ---------------------------------------------
// GET ALL OF A PRO PLAYERS MATCHES
--------------------------------------------- */
app.get('/matchlist/:encryptedAccountId', (req, res) => {
const encryptedAccountId = req.params.encryptedAccountId;
fetch(`${api_path}/match/v4/matchlists/by-account/${encryptedAccountId}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "matchlist" ERROR, GABE! -----');
console.log(err);
});
});
/* ---------------------------------------------
// FIND A SPECIFIC MATCH
--------------------------------------------- */
app.get('/matches/:matchId', (req, res) => {
const matchId = req.params.matchId;
fetch(`${api_path}/match/v4/matches/${matchId}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "matches" ERROR, GABE! -----');
console.log(err);
});
});
/* ---------------------------------------------
// GET WINS/LOSSES/POINTS DATA FOR A PLAYER
--------------------------------------------- */
// update "positions" to be "entries" ???
app.get('/entries/:encryptedSummonerId', (req, res) => {
const encryptedSummonerId = req.params.encryptedSummonerId;
fetch(`${api_path}/league/v4/entries/by-summoner/${encryptedSummonerId}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "positions" ERROR, GABE! -----');
console.log(err);
});
});
/* ---------------------------------------------
// GET A PRO PLAYERS CURRENT CHAMPION MASTERIES LEVEL
--------------------------------------------- */
app.get('/summoner-masteries/:encryptedSummonerId', (req, res) => {
const encryptedSummonerId = req.params.encryptedSummonerId;
fetch(`${api_path}/champion-mastery/v4/champion-masteries/by-summoner/${encryptedSummonerId}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "summoner-masteries" ERROR, GABE! -----');
console.log(err);
});
});
/* ---------------------------------------------
// GET A PRO PLAYERS CHAMPION MASTERY SCORE
--------------------------------------------- */
app.get('/scores/:encryptedSummonerId', (req, res) => {
const encryptedSummonerId = req.params.encryptedSummonerId;
fetch(`${api_path}/champion-mastery/v4/scores/by-summoner/${encryptedSummonerId}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "scores" ERROR, GABE! -----');
console.log(err);
});
});
/* ---------------------------------------------
// GET ALL PLAYERS FROM A SPECIFIC SOLO QUEUE CHALLENGER LEAGUE
--------------------------------------------- */
app.get('/challenger-queue/:queue', (req, res) => {
const queue = req.params.queue;
fetch(`${api_path}/league/v4/challengerleagues/by-queue/${queue}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "queue-leagues" ERROR, GABE! -----');
console.log(err);
});
});
/* ---------------------------------------------
// GET A PRO PLAYERS MATCH TIMELINES
// (i.e. HEATMAP COORDS/DATA?)
--------------------------------------------- */
app.get('/match-timelines/:matchId', (req, res) => {
const matchId = req.params.matchId;
fetch(`${api_path}/match/v4/timelines/by-match/${matchId}?api_key=${riot}`)
.then((res) => {
return (res.text());
})
.then((body) => {
const results = JSON.parse(body);
res.send(results);
})
.catch((err) => {
console.log('----- YOU HAVE A BACKEND "match-timelines" ERROR, GABE! -----');
console.log(err);
});
});
app.listen(PORT, () => {
console.log('--- END OF APP.js FILE ---');
console.log(__dirname);
console.log(`listening on PORT: ${PORT}`);
console.log('--- END OF APP.js FILE ---');
});