大家,早安,
我是一名年轻的开发人员,我非常喜欢 nodejs,我尝试通过创建小型个人应用程序来自学。因此,我创建了一个使用 RIOT API 的应用程序,以显示昵称、联赛及其积分、赢得或失去的积分。它适用于一个人,但当我决定让它适用于几个人时,它就卡住了。在网上我们谈论异步但作为一个新手我迷路了,这是我的代码,首先感谢您的阅读,并提前提供帮助。
Ps:对不起我的英语不好:D
var https = require('https');
var http = require('http');
const EU = 'https://euw1.api.riotgames.com/lol/league/v4/entries/by-summoner/';
const NA1 = 'https://na1.api.riotgames.com/lol/league/v4/entries/by-summoner/';
const URLKEY = '?api_key=';
const Thomas = 'ZHd2VXBU5vuGumSIty1WXq5OqWu0XpAfXG8TyjIgDSwAGlU';
const John = 'DkcxPRTDj1WDUMiOn_RN16AtGqNvKKig6SItWxoc3FhmIfQ';
const MaximeG = 'LzIGCODKziH7E4QvOJ0cFHL2MJ3B00pukIShOH8qYemKlXs';
var server = http.createServer(function(req, res){
let data = '';
const key = '';
// Doesn't work when you put multiple players :(
const PLAYERID= [Thomas,John];
PLAYERID.forEach(id => {
console.log('Here the different id');
console.log(id);
console.log('continuation');
https.get(EU + id + URLKEY + key,
(rr)=>{
rr.on('data', (chunk) => {
console.log(chunk.toString());
data += chunk;
});
rr.on('end', () => {
let result = JSON.parse(data);
console.log('result before json');
console.log(result);
console.log('result after parse');
console.log(data);
let output = [''];
for(let i=0;i<result.length;i++){
output += "Name : "+result[i].summonerName+ " League : "+result[i].queueType+"\n\tRank : "+result[i].tier+" "+result[i].rank+" "+result[i].leaguePoints+" LP Nombre de victoires : "+result[i].wins+" Nombre de defaites : "+result[i].losses+" \n";
console.log(output);
}
res.end(output);
});
});
});
}).listen(8080);