2024-05-30 13:33:49 +02:00
|
|
|
import { logger } from "./utils/logger";
|
|
|
|
|
|
|
|
logger.info("Starting up...");
|
|
|
|
|
2023-05-19 15:22:48 -03:00
|
|
|
import http from "http";
|
|
|
|
import https from "https";
|
|
|
|
import fs from "node:fs";
|
|
|
|
import { app } from "./app";
|
2024-12-29 23:34:26 +01:00
|
|
|
import { config, validateConfig } from "./services/configService";
|
2024-12-23 22:48:16 +01:00
|
|
|
import { registerLogFileCreationListener } from "@/src/utils/logger";
|
2024-12-31 01:41:47 +01:00
|
|
|
import mongoose from "mongoose";
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2025-03-20 05:36:09 -07:00
|
|
|
// Patch JSON.stringify to work flawlessly with Bigints. Yeah, it's not pretty.
|
|
|
|
// TODO: Might wanna use json-with-bigint if/when possible.
|
|
|
|
{
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
|
|
(BigInt.prototype as any).toJSON = function (): string {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
|
|
return "<BIGINT>" + this.toString() + "</BIGINT>";
|
|
|
|
};
|
|
|
|
const og_stringify = JSON.stringify;
|
2025-03-23 09:06:08 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
JSON.stringify = (obj: any, replacer?: any, space?: string | number): string => {
|
|
|
|
return og_stringify(obj, replacer as string[], space)
|
|
|
|
.split(`"<BIGINT>`)
|
|
|
|
.join(``)
|
|
|
|
.split(`</BIGINT>"`)
|
|
|
|
.join(``);
|
2025-03-20 05:36:09 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-12-23 22:48:16 +01:00
|
|
|
registerLogFileCreationListener();
|
2024-12-29 23:34:26 +01:00
|
|
|
validateConfig();
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2024-12-31 01:41:47 +01:00
|
|
|
mongoose
|
|
|
|
.connect(config.mongodbUrl)
|
|
|
|
.then(() => {
|
|
|
|
logger.info("Connected to MongoDB");
|
2024-05-22 23:32:11 +02:00
|
|
|
|
2024-12-31 01:41:47 +01:00
|
|
|
const httpPort = config.httpPort || 80;
|
|
|
|
const httpsPort = config.httpsPort || 443;
|
|
|
|
const options = {
|
|
|
|
key: fs.readFileSync("static/certs/key.pem"),
|
|
|
|
cert: fs.readFileSync("static/certs/cert.pem")
|
|
|
|
};
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2025-02-24 20:56:34 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
2024-12-31 01:41:47 +01:00
|
|
|
http.createServer(app).listen(httpPort, () => {
|
|
|
|
logger.info("HTTP server started on port " + httpPort);
|
2025-02-24 20:56:34 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
2024-12-31 01:41:47 +01:00
|
|
|
https.createServer(options, app).listen(httpsPort, () => {
|
|
|
|
logger.info("HTTPS server started on port " + httpsPort);
|
2024-12-23 22:48:16 +01:00
|
|
|
|
2024-12-31 01:41:47 +01:00
|
|
|
logger.info(
|
|
|
|
"Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
|
|
|
|
);
|
|
|
|
});
|
2024-12-23 22:48:16 +01:00
|
|
|
});
|
2024-12-31 01:41:47 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error instanceof Error) {
|
|
|
|
logger.error(`Error connecting to MongoDB server: ${error.message}`);
|
|
|
|
}
|
|
|
|
process.exit(1);
|
2024-12-23 22:48:16 +01:00
|
|
|
});
|