-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (44 loc) · 1.84 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
const express = require("express");
const app = express();
const compression = require("compression");
const fs = require("fs");
const config = require("./Config/config.json");
const functions = require("./utils/functions");
const log = require("./utils/log");
const personaManager = require("./services/personaManager");
const path = require("path");
global.httpPORT = 3550;
global.xmppPORT = 5222;
personaManager.removeActivePersona();
app.use((req, res, next) => {
res.set("Connection", "close");
req.body = "";
req.on("data", (chunk) => req.body += chunk);
req.on("end", () => next());
});
app.use((req, res, next) => {
if (config.LogRequests) log.backend(`${req.method} ${req.url} ${req.body}`);
next();
});
app.use(compression({ threshold: 0 }));
for (let fileName of fs.readdirSync(path.join(__dirname, "routes"))) {
if (fileName.startsWith("Main")) continue;
app.use("/Engine.svc", require(`./routes/${fileName}`));
}
app.use("/Engine.svc", require("./routes/Main"));
app.on("error", async (err) => {
if (err.code == "EADDRINUSE") {
log.error("BACKEND", `Port ${global.httpPORT} is already in use!`);
log.error("BACKEND", `Closing in 3 seconds...`);
await functions.sleep(3000);
process.exit(0);
} else throw err;
});
app.listen(global.httpPORT, async () => {
log.backend(`NFS World Offline Server by Lawin started listening on port ${global.httpPORT}`);
console.log(`\nLaunch the game either by:`
+ `\n1) Adding the server to the Soapbox Race World Launcher by the url "http://127.0.0.1:${global.httpPORT}/Engine.svc".`
+ `\n2) or by using these launch args "nfsw.exe US http://127.0.0.1:${global.httpPORT}/Engine.svc a 1".\n`);
await require("./xmpp");
require("./commands");
});