- โ Riot API๋ฅผ ์ธ์ฆ
- ๐XMLHttpRequest์ ์ด์ฉํด์ Riot API ๋ฐ์ดํฐ ํ์ฑ
- Express๋ฅผ ์ด์ฉํด์ Front์ ๋ฐ์ดํฐ ๋๊ธฐ๊ธฐ
- ๋ด๋ชจํผ์ฆ์ ์ด์ฉํ์ฌ ์ฌ์ดํธ ๊พธ๋ฏธ๊ธฐ
์๋ธํํฐ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์์ง ์์งํ๊ฒ ์์ด์ XMLHttpRequest์ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ํ์ฑํ๊ธฐ๋ก ํ์๋ค.
๋์ค์ ์ฌ์ดํธ๋ฅผ ๋ค๋ฌ์๋ Spring boot๋ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ํ์ฑํ๋๊ฑธ ๊ณต๋ถํด๋ณด๋๋ก ํ์.
Riot Developer์ฌ์ดํธ์์ ๊ฐ์ ธ์ฌ ๋งํ ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ค๋ด ๋ณด์.
SUMMONER-V4 ์ํ์ฌ์ ๋ณด
- /lol/summoner/v4/summoners/by-name/{summonerName}
LEAGUE-V4 ๋ฆฌ๊ทธ ์ ๋ณด
- /lol/league/v4/entries/by-summoner/{encryptedSummonerId}
Match-V4 ์ํ์ฌ ์ ์ ๋ฆฌ์คํธ
- /lol/match/v5/matches/by-puuid/{puuid}/ids
- /lol/match/v5/matches/{matchId}
CHAMPION-V3 ์ฑํผ์จ ์ ๋ณด
- /lol/platform/v3/champion-rotations
RIOT APIํค๋ฅผ ๋ฐ์๋ค๋ฉด ๊ฐ๋ฐ์์ฌ์ดํธ์์ ๋ฐ์ดํฐ๊ฐ ์ด๋ป๊ฒ ๋ ์์ค๋์ง ๋ฏธ๋ฆฌ ํ
์คํธํด ๋ณผ ์ ์๋ค
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return JSON.parse(xmlHttp.responseText);
}
์์ฒญํ ๋ฐ์ดํฐ๋ฅผ JSON๋ฐ์ดํฐ๋ก ํ์ฑํ๋ ํจ์์ด๋ค. ๊ฐ๋จํ๊ฒ JSON๊ฐ์ฒด ํํ๋ก ๋ฐ๊ฟ ์ ์์๋ค.
์๋ ์ฌ์ง์ ํ์ฑํ JSON๋ฐ์ดํฐ์ด๋ค.
์์ ๊ฐ์ด ๊ธ์ด์จ ๋ฐ์ดํฐ๋ฅผ ๋ด๊ฐ ๋ง๋ ๋ชจ๋์ ํ๋์ผ๋ก ๋๊ฒจ์ฃผ๊ธฐ๋ก ํ์๋ค.
search_summoner.js File
const template = require('./lib/template.js');
...
html = template.HTML(
results
,list
)
res.send(html);
template.js
module.exports = {
HTML:function (SummonerObject,list) {
let queType ="UnRanked";
let soloInfo ='';
let soloImg;
let queTypeTeam ="UnRanked";
let teamInfo ='UnRanked';
let teamIMG;
if(SummonerObject[0].tier1==undefined){
console.log('์คํ?');
soloImg='undefined'
}else{
queType ="์๋ก๋ญํฌ";
soloInfo = SummonerObject[0].tier1 + ' ' + SummonerObject[0].rank1 + ' ' + SummonerObject[0].leaguePoints1 + '<br>' +
SummonerObject[0].wins1+'์น' +SummonerObject[0].losses1+'ํจ';
soloImg = SummonerObject[0].tier1;
}
if(SummonerObject[0].tier2==undefined){
teamIMG='undefined';
}else{
queTypeTeam ="ํ ๋ญํฌ";
teamInfo = SummonerObject[0].tier2 +'  '+SummonerObject[0].rank2 +'  '+SummonerObject[0].leaguePoints2+'<br>'+
SummonerObject[0].wins2+'์น' +SummonerObject[0].losses2+'ํจ';
teamIMG = SummonerObject[0].tier2;
}
return`
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="what.css" rel="stylesheet">
<title>Document</title>
</head>
<script src="../search_summoner.js"></script>
<body>
<header>
<div class="profile">
<div id="profile_left">
<span class="face">
<img src="profileicon/${SummonerObject[0].profileIconId}.png" alt="">
</span>
<span class="profile_left">
<div>
<span class="name">${SummonerObject[0].summonerName}</span>
</div>
<div>
<form action="http://localhost:3000/search" id="form_style" method="get">
<div class="search_form">
<input type="text" id="search_summoner" placeholder="์ํ์ฌ ์ด๋ฆ์ ์
๋ ฅํ์ธ์" name="id">
<Button type="submit" id="btn_search">๊ฒ์</Button>
</div>
</form>
</div>
<div>
<button id="reload">์ ์ ๊ฐฑ์ </button>
</div>
</span>
</div>
<div id="logo">
<img src="logo.png" alt="">
</div>
</div>
<div class="ranks">
<span class="rank">
<span class="tier">
<div>${queType}</div>
<img style='width:10vh' src="ranked-emblems/${soloImg}.png" alt="">
</span>
<span>
${soloInfo}
</span>
</span>
<span class="rank">
<span class="tier">
<div>${queTypeTeam}</div>
<img src="ranked-emblems/${teamIMG}.png" alt="">
</span>
<span>
${teamInfo}
</span>
</span>
</div>
</header>
${list}
</body>
</html>
`;
}
์ ์์ ์ผ๋ก ๋ฐ์ดํฐ๊ฐ ์ ๋ฌ๋๊ฑธ ํ์ธํ ์ ์์๋ค.