-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
74 lines (67 loc) · 1.77 KB
/
index.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
const {
requestURL,
requestUserAgent,
isBehindProxy,
rateLimitWindowDurationMinutes,
rateLimitWindowMax,
serverlistQueryIntervalSeconds,
listenPort,
uniqueUUID,
} = require("../config/config.json");
const fs = require("fs");
const app = require("express")();
const cors = require("cors");
const rateLimit = require("express-rate-limit");
const limiter = rateLimit({
windowMs: rateLimitWindowDurationMinutes * 60 * 1000,
max: rateLimitWindowMax,
});
const axios = require("axios").default;
const port = process.env.PORT || listenPort;
if (
uniqueUUID.match(
"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
) == null
) {
console.error(
"Something is wrong with the UUID:( https://www.regextester.com/99148"
);
process.exit(0);
}
const routes = require("./routes/");
app.use("/api", routes);
app.use(limiter);
app.use(cors);
if (isBehindProxy) {
app.set("trust proxy", 1);
console.log("Trust proxy enabled (this means you are using a proxy)");
}
app.listen(port, () => {
getInfo();
setInterval(getInfo, serverlistQueryIntervalSeconds * 1000);
console.log(`Listening on port ${port}`);
});
function getInfo() {
axios
.get(requestURL, { headers: { "User-Agent": requestUserAgent } })
.then((resp) => {
fs.writeFileSync(
"./storage/raw.json",
JSON.stringify(resp.data, null, 2)
);
})
.catch((err) => {
console.error(err);
});
axios
.get("https://static.ren-x.com/launcher_data/version/release.json")
.then((resp) => {
fs.writeFileSync(
"./storage/version.json",
JSON.stringify(resp.data, null, 2)
);
})
.catch((err) => {
console.error(err);
});
}