Make HttpServer singleton-based

This commit is contained in:
memetrollsXD 2022-07-26 17:53:59 +02:00
parent 203a6b9fa2
commit 8779554ed2
No known key found for this signature in database
GPG Key ID: 105C2F3417AC32CD
2 changed files with 10 additions and 2 deletions

View File

@ -17,8 +17,9 @@ const HTTPS_CONFIG = {
export default class HttpServer { export default class HttpServer {
private readonly server; private readonly server;
public static instance: HttpServer;
public constructor() { private constructor() {
this.server = express(); this.server = express();
this.server.use(express.json()); this.server.use(express.json());
this.server.route('/*').all((req, res) => { this.server.route('/*').all((req, res) => {
@ -39,4 +40,11 @@ export default class HttpServer {
c.log(`Listening on ${Config.HTTP.HTTP_HOST}:${Config.HTTP.HTTP_PORT}`); c.log(`Listening on ${Config.HTTP.HTTP_HOST}:${Config.HTTP.HTTP_PORT}`);
}); });
} }
public static getInstance(): HttpServer {
if (!HttpServer.instance) {
HttpServer.instance = new HttpServer();
}
return HttpServer.instance;
}
} }

View File

@ -10,4 +10,4 @@ const c = new Logger("CrepeSR");
c.log(`Starting CrepeSR...`); c.log(`Starting CrepeSR...`);
Interface.start(); Interface.start();
const http = new HttpServer(); HttpServer.getInstance();