forked from NeoniteDev/NeoniteV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
68 lines (53 loc) · 1.74 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
const express = require("express");
const bodyParser = require("body-parser");
const fs = require("fs");
const errors = require("./structs/errors");
const { v4: uuidv4 } = require("uuid");
const { ApiException } = errors;
const { Console } = require("console");
const version = "2.7.2";
const NeoLog = require('./structs/NeoLog')
global.xmppClients = [];
global.port = 5595;
global.LobbyBotPort = 80;
(function () {
"use strict";
String.prototype.format = function () {
const args = arguments[0] instanceof Array ? arguments[0] : arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != "undefined" ? args[number] : match;
});
};
require('./xmpp')
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.set("etag", false);
app.use("/", express.static("public"));
fs.readdirSync(`${__dirname}/managers`).forEach(route => {
require(`${__dirname}/managers/${route}`)(app, port);
})
app.use((req, res, next) => {
next(new ApiException(errors.com.epicgames.common.not_found));
})
app.use((err, req, res, next) => {
let error = null;
if (err instanceof ApiException) {
error = err;
} else {
const trackingId = req.headers["x-epic-correlation-id"] || uuidv4();
error = new ApiException(errors.com.epicgames.common.server_error).with(trackingId);
console.error(trackingId, err);
}
error.apply(res);
});
app.listen(port, () => {
if (process.argv.includes("--test"))
{
require(`${__dirname}/.github/test/testing.js`)(app);
process.exit(0)
}
NeoLog.Log(`v${version} is listening on port ` + port || 5595 + "!");
});
module.exports = app;
}());