-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (48 loc) · 1.58 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
const express = require('express')
const app = express()
const port = process.env.PORT || 80;
const fetch = require('node-fetch');
let settings = { method: "Get" };
const url = "https://static.nvidiagrid.net/supported-public-game-list/gfnpc.json?JSON"
const header1 = "<h1><u>Geforce Now Game List</u></h1>"
const header2 = `
<h3>This is a table directly from the current Nvidia's
<a href="https://static.nvidiagrid.net/supported-public-game-list/gfnpc.json?JSON"> JSON data here.</a>
<br>
💕 Please feel free to contribute code to the project
<a href="https://github.com/lettuceboop/geforce-now-gameslist">here</a> 💕
</h3>`
app.get('/', function (req, res) {
fetch(url, settings)
.then(res => res.json())
.then((json) => {
res.send(header1 + header2 + json2table(json, 'table'))
});
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
function json2table(json, classes) {
var cols = Object.keys(json[0]);
var headerRow = '';
var bodyRows = '';
classes = classes || '';
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
cols.map(function(col) {
headerRow += '<th>' + capitalizeFirstLetter(col) + '</th>';
});
json.map(function(row) {
bodyRows += '<tr>';
cols.map(function(colName) {
bodyRows += '<td>' + row[colName] + '</td>';
})
bodyRows += '</tr>';
});
return '<table class="' +
classes +
'"><thead><tr>' +
headerRow +
'</tr></thead><tbody>' +
bodyRows +
'</tbody></table>';
}