-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (28 loc) · 1.01 KB
/
Copy pathserver.js
File metadata and controls
37 lines (28 loc) · 1.01 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
const https = require('https');
const http = require('http');
const url = require('url');
const apiKey = '';
const PORT = 8080;
const server = http.createServer((request, response) => {
const parts = url.parse(request.url, true);
const query = parts.query;
const summonerName = query.summonerName;
callAPI(summonerName, response)
});
server.listen(PORT, () => console.log("Server is listening on port %s", PORT));
function callAPI(summonerName, response) {
const url = 'https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/' + summonerName + '?api_key=' + apiKey;
https.get(url, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
response.end(data);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}