-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
40 lines (33 loc) · 1.12 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
//starter express file
const express = require('express');
const app = express();
const { generateLeaderboard } = require('./functions/generateLeaderboard');
const { updateLeaderboardJob } = require('./jobs/updateOSLeaderboard');
const fs = require('fs');
const cors = require('cors');
const port = process.env.PORT || 3000;
require('dotenv').config()
app.use(express.json());
app.use(cors());
generateLeaderboard();
updateLeaderboardJob();
let default_json = { "leaderboard": [], "success": true, "updatedAt": null, "generated": false };
fs.writeFile('leaderboard.json', JSON.stringify(default_json), 'utf8', function (err) {
if (err) throw err;
console.log('leaderboard.json was reset');
});
app.get('/', (req, res) => {
res.send('Hello World');
});
app.get("/OSLeaderboard", (req, res) => {
console.log("got the request");
fs.readFile('leaderboard.json', 'utf8', function (err, data) {
if (err) throw err;
console.log("sending response");
let obj = JSON.parse(data);
res.send(obj);
});
});
app.listen(port, "0.0.0.0", () => {
console.log('Server started on port 3000');
});