code improvements and clientsettings fallback

This commit is contained in:
Lawin0129
2022-06-11 20:10:08 +01:00
parent b1f3200fa2
commit 993a562c9f
13 changed files with 1725 additions and 2534 deletions

View File

@@ -2,10 +2,12 @@ const Express = require("express");
const express = Express();
const fs = require("fs");
const path = require("path");
const cookieParser = require("cookie-parser");
express.use(Express.json());
express.use(Express.urlencoded({ extended: true }));
express.use(Express.static('public'));
express.use(cookieParser());
express.use(require("./structure/party.js"));
express.use(require("./structure/discovery.js"))
@@ -24,13 +26,26 @@ express.use(require("./structure/cloudstorage.js"));
express.use(require("./structure/mcp.js"));
const port = process.env.PORT || 3551;
express.listen(port, console.log("LawinServer started listening on port", port));
require("./structure/xmpp.js");
express.listen(port, () => {
console.log("LawinServer started listening on port", port);
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer"))) fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer"));
require("./structure/xmpp.js");
}).on("error", (err) => {
if (err.code == "EADDRINUSE") console.log(`\x1b[31mERROR\x1b[0m: Port ${port} is already in use!`);
else throw err;
// keep this at the end of the code thanks
express.all("*", async (req, res) => {
process.exit(0);
});
try {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer"))) fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer"));
} catch (err) {
// fallback
if (!fs.existsSync(path.join(__dirname, "ClientSettings"))) fs.mkdirSync(path.join(__dirname, "ClientSettings"));
}
// if endpoint not found, return this error
express.use((req, res, next) => {
var XEpicErrorName = "errors.com.lawinserver.common.not_found";
var XEpicErrorCode = 1004;
@@ -47,5 +62,4 @@ express.all("*", async (req, res) => {
"originatingService": "any",
"intent": "prod"
});
res.end();
});