small clean
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import express from 'express';
|
||||
import express, {Application} from 'express';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
import {Server as HttpServer, Socket} from 'socket.io';
|
||||
import {Server as SocketServer, Socket} from 'socket.io';
|
||||
import config from './app/utilities/config';
|
||||
import prisma from './app/utilities/prisma';
|
||||
import api from "./app/utilities/api";
|
||||
@ -11,9 +11,9 @@ import ZoneManager from "./app/ZoneManager";
|
||||
|
||||
export class Server
|
||||
{
|
||||
private readonly app: express.Application;
|
||||
private readonly app: Application;
|
||||
private readonly server: any;
|
||||
private readonly io: HttpServer;
|
||||
private readonly io: SocketServer;
|
||||
|
||||
/**
|
||||
* Creates an instance of GameServer.
|
||||
@ -24,7 +24,7 @@ export class Server
|
||||
this.app.use(express.json());
|
||||
this.app.use(express.urlencoded({ extended: true }));
|
||||
this.server = http.createServer(this.app)
|
||||
this.io = new HttpServer(this.server);
|
||||
this.io = new SocketServer(this.server);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,12 +70,16 @@ export class Server
|
||||
const eventsPath = path.join(__dirname, 'app', 'events');
|
||||
try {
|
||||
const files: string[] = await fs.promises.readdir(eventsPath);
|
||||
for (const file of files) {
|
||||
const module = await import(path.join(eventsPath, file));
|
||||
module.default(socket, this.io);
|
||||
}
|
||||
await Promise.all(files.map(async (file) => {
|
||||
try {
|
||||
const module = await import(path.join(eventsPath, file));
|
||||
module.default(socket, this.io);
|
||||
} catch (error: any) {
|
||||
console.error(`[❌] Failed to load event handler ${file}: ${error.message}`);
|
||||
}
|
||||
}));
|
||||
} catch (error: any) {
|
||||
throw new Error('[❌] Failed to load event handlers: ' + error.message);
|
||||
throw new Error('[❌] Failed to read event handlers directory: ' + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user