-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
75 lines (61 loc) · 2.02 KB
/
server.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var express = require('express');
var exphbs = require('express-handlebars');
var bodyParser = require('body-parser');
var rls = require('./lib/index.js');
var secret = require('./secret.json');
var app = express();
var port = process.env.PORT || 8000;
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
app.set('view engine', 'handlebars');
app.use(bodyParser.json());
app.use(express.static('public'));
app.get('/', function (req, res) {
res.status(200).render('homepage');
});
app.get('/getPlayer', function (req, res) {
console.log("Recieved a getPlayer request:", req.body);
var client = new rls.Client({
token: secret.api_key
});
if (req.body) {
console.log("GET REQ");
}
client.searchPlayers("Olsencar", 3, function (status, data) {
if(status === 200){
console.log("-- Player Data:");
console.log(" Display name: " + data.displayName);
console.log(" Goals: " + data.stats.goals);
res.status(200).send("Success");
} else {
console.log("-- getPlayer failed: " + status);
res.status(500).send("Error retrieving player name");
}
});
// client.getPlatformsData(function(status, data){
// if(status === 200){
// console.log("-- Platforms data:");
// console.log(data);
// }
// });
// client.getSeasonsData(function(status, data){
// if(status === 200){
// console.log("-- Seasons data:");
// console.log(data);
// }
// });
// client.getPlaylistsData(function(status, data){
// if(status === 200){
// console.log("-- Playlists data:");
// console.log(data);
// }
// });
// client.getTiersData(function(status, data){
// if(status === 200){
// console.log("-- Tiers data:");
// console.log(data);
// }
// });
});
app.listen(port, function () {
console.log("== Server listening on port:", port);
});