Showing
1 changed file
with
53 additions
and
0 deletions
RUTROLL/router/main(1).js
0 → 100644
1 | +const express = require('express'); | ||
2 | +const router = express.Router(); | ||
3 | +const request = require("request"); | ||
4 | +const urlenconde = require('urlencode'); | ||
5 | +const apikey = "RGAPI-816bb9a0-615c-41e0-a01e-f5e0bb68c3a6"//api | ||
6 | +router.get('/search/summoner/:username/', function (req, res) { | ||
7 | + //롤 api url | ||
8 | + const name = req.params.username; | ||
9 | + var nameUrl = "https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/" + urlenconde(name) + "?api_key=" + apikey; | ||
10 | + request(nameUrl, function (error, response, body) { | ||
11 | + var info_summoner_json = JSON.parse(body); | ||
12 | + const summonerId = info_summoner_json.id; | ||
13 | + const rankUrl = `https://kr.api.riotgames.com/tft/league/v1/entries/by-summoner/${urlenconde(summonerId)}?api_key=${apikey}`; | ||
14 | + request(rankUrl, function (error, response, body) { | ||
15 | + const rank_info = JSON.parse(body); | ||
16 | + res.json({ | ||
17 | + status: 200, | ||
18 | + data: { | ||
19 | + summoner: info_summoner_json, | ||
20 | + leagueList: rank_info | ||
21 | + } | ||
22 | + }); | ||
23 | + }); | ||
24 | + }); | ||
25 | +}); | ||
26 | + | ||
27 | +router.get('/search/match/:puuid', function (req, res) { | ||
28 | + //api url | ||
29 | + const puuid = req.params.puuid; | ||
30 | + const matchIdUrl = `https://asia.api.riotgames.com/tft/match/v1/matches/by-puuid/${puuid}/ids?api_key=${apikey}`; | ||
31 | + request(matchIdUrl, function (error, response, body) { | ||
32 | + const matchIdList = JSON.parse(body); | ||
33 | + const promiseList = []; | ||
34 | + matchIdList.forEach(matchId => { | ||
35 | + promiseList.push(new Promise((resolve, reject) => { | ||
36 | + const matchURL = `https://asia.api.riotgames.com/tft/match/v1/matches/${matchId}?api_key=${apikey}`; | ||
37 | + request(matchURL, function (error, response, body) { | ||
38 | + const match = JSON.parse(body); | ||
39 | + resolve(match); | ||
40 | + }); | ||
41 | + })); | ||
42 | + Promise.all(promiseList).then(matches => { | ||
43 | + res.json({ | ||
44 | + status: 200, | ||
45 | + data: { | ||
46 | + matchList: matches | ||
47 | + } | ||
48 | + }); | ||
49 | + }) | ||
50 | + }); | ||
51 | + }); | ||
52 | + | ||
53 | + module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment