main(1).js
1.86 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
const express = require('express');
const router = express.Router();
const request = require("request");
const urlenconde = require('urlencode');
const apikey = "RGAPI-816bb9a0-615c-41e0-a01e-f5e0bb68c3a6"//api
router.get('/search/summoner/:username/', function (req, res) {
//롤 api url
const name = req.params.username;
var nameUrl = "https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/" + urlenconde(name) + "?api_key=" + apikey;
request(nameUrl, function (error, response, body) {
var info_summoner_json = JSON.parse(body);
const summonerId = info_summoner_json.id;
const rankUrl = `https://kr.api.riotgames.com/tft/league/v1/entries/by-summoner/${urlenconde(summonerId)}?api_key=${apikey}`;
request(rankUrl, function (error, response, body) {
const rank_info = JSON.parse(body);
res.json({
status: 200,
data: {
summoner: info_summoner_json,
leagueList: rank_info
}
});
});
});
});
router.get('/search/match/:puuid', function (req, res) {
//api url
const puuid = req.params.puuid;
const matchIdUrl = `https://asia.api.riotgames.com/tft/match/v1/matches/by-puuid/${puuid}/ids?api_key=${apikey}`;
request(matchIdUrl, function (error, response, body) {
const matchIdList = JSON.parse(body);
const promiseList = [];
matchIdList.forEach(matchId => {
promiseList.push(new Promise((resolve, reject) => {
const matchURL = `https://asia.api.riotgames.com/tft/match/v1/matches/${matchId}?api_key=${apikey}`;
request(matchURL, function (error, response, body) {
const match = JSON.parse(body);
resolve(match);
});
}));
Promise.all(promiseList).then(matches => {
res.json({
status: 200,
data: {
matchList: matches
}
});
})
});
});
module.exports = router;