-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
153 lines (139 loc) · 4.1 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const express = require("express");
const app = express();
const path = require("path");
const fetch = require("node-fetch");
// require("dotenv").config();
const Key = require('./src/config/keys');
const { debug } = require("console");
const PORT = process.env.PORT || 8080; // process.env accesses heroku's environment variables
app.use(express.static("dist"));
app.get("/", (request, res) => {
res.sendFile(path.join(__dirname, "./dist/index.html"));
});
app.get("/pubg/gamertag/:name", (req, res) => {
const playerByNameInit = {
method: 'get',
headers: {
Authorization: `Bearer ${ Key.pubgAPI }`,
Accept: 'application/vnd.api+json'
}
}
let request = new fetch.Request(`https://api.pubg.com/shards/xbox/players?filter[playerNames]=${ req.params.name }`, playerByNameInit);
return fetch(request).then(function(response) {
if(response.ok) {
return response.json().then(json => {
res.send(json.data[0].relationships.matches.data);
})
}
})
})
app.get("/pubg/matches/:matchId", (req, res) => {
// make api call using fetch
const gameInit = {
method: 'get',
headers: {
Accept: 'application/vnd.api+json'
}
}
// debugger
let request = new fetch.Request(`https://api.pubg.com/shards/xbox/matches/${ req.params.matchId }`, gameInit);
// debugger
return fetch(request).then(function(response) {
if(response.ok) {
return response.json().then(match => {
res.send(match)
})
}
})
});
app.get("/pubg/telemetry", (req, res) => {
const telemetryInit = {
method: 'get',
headers: {
Accept: 'application/vnd.api+json'
}
}
let request = new fetch.Request(req.query.url, telemetryInit);
// debugger
return fetch(request).then(function(response) {
if(response.ok) {
return response.json().then(json => {
res.send(json)
})
}
})
})
app.get("/oauth", (req, res) => {
const oauthInit = {
method: 'post',
// scope: 'user:read:email'
}
let request = new fetch.Request(`https://id.twitch.tv/oauth2/token?client_id=${ Key.twitchAPI }&client_secret=${ Key.clientSECRET }&grant_type=client_credentials`, oauthInit);
return fetch(request).then(function(response) {
if(response.ok) {
return response.json().then(json => {
res.send(json)
})
}
})
})
app.get("/twitch/:user", (req,res) => {
const twitchUserInit = {
method: 'get',
headers: {
'Authorization': `Bearer ${ Key.oAUTH }`,
'Client-Id': `${ Key.twitchAPI }`
}
}
let request = new fetch.Request(`https://api.twitch.tv/helix/users?login=${ req.params.user }`, twitchUserInit);
return fetch(request).then(function(response) {
if(response.ok){
return response.json().then(json=> {
res.send(json)
})
} else {
// console.log(response);
res.send(false)
}
})
})
app.get("/twitchvideos/:userId", (req, res) => {
const twitchVideosInit = {
method: 'get',
headers: {
'Authorization': `Bearer ${ Key.oAUTH }`,
'Client-Id': `${ Key.twitchAPI }`
}
}
let request = new fetch.Request(`https://api.twitch.tv/helix/videos?user_id=${ req.params.userId }`, twitchVideosInit);
return fetch(request).then(function(response) {
if(response.ok) {
return response.json().then(json => {
res.send(json)
})
}
})
})
app.get("/pubgvideos/:videoId", (req, res)=> {
const twitchPubgInit = {
method: 'get',
headers: {
"Accept": "application/vnd.twitchtv.v5+json",
'Client-Id': `${ Key.twitchAPI }`
}
}
let request = new fetch.Request(`https://api.twitch.tv/kraken/videos/${ req.params.videoId }`, twitchPubgInit);
return fetch(request).then(function(response) {
if(response.ok) {
return response.json().then(json => {
res.send(json)
})
} else {
res.send(false)
}
})
})
app.listen(PORT, () => {
console.log(__dirname);
console.log(`listening on ${PORT}`);
});