my 13th reason
This commit is contained in:
@ -1,19 +1,21 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import express, {Application} from 'express';
|
||||
import http from 'http';
|
||||
import {createServer as httpServer} from 'http';
|
||||
import {addAuthRoutes} from './app/utilities/Http';
|
||||
import cors from 'cors';
|
||||
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";
|
||||
import {Server as SocketServer} from 'socket.io';
|
||||
import {TSocket} from "./app/types/TSocket";
|
||||
import config from './app/utilities/Config';
|
||||
import prisma from './app/utilities/Prisma';
|
||||
import ZoneManager from "./app/ZoneManager";
|
||||
import UserManager from "./app/UserManager";
|
||||
import {Authentication} from "./app/middleware/Authentication";
|
||||
|
||||
export class Server
|
||||
{
|
||||
private readonly app: Application;
|
||||
private readonly server: any;
|
||||
private readonly http: any;
|
||||
private readonly io: SocketServer;
|
||||
|
||||
/**
|
||||
@ -24,8 +26,9 @@ export class Server
|
||||
this.app.use(cors());
|
||||
this.app.use(express.json());
|
||||
this.app.use(express.urlencoded({ extended: true }));
|
||||
this.server = http.createServer(this.app)
|
||||
this.io = new SocketServer(this.server);
|
||||
this.http = httpServer(this.app)
|
||||
this.io = new SocketServer(this.http);
|
||||
this.io.use(Authentication)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,14 +49,14 @@ export class Server
|
||||
|
||||
// Start the server
|
||||
try {
|
||||
await this.server.listen(config.PORT);
|
||||
await this.http.listen(config.PORT);
|
||||
console.log('[✅] Socket.IO running on port', config.PORT);
|
||||
} catch (error: any) {
|
||||
throw new Error(`[❌] Socket.IO failed to start: ${error.message}`);
|
||||
}
|
||||
|
||||
// Add API routes
|
||||
await api.addAuthRoutes(this.app);
|
||||
// Add http API routes
|
||||
await addAuthRoutes(this.app);
|
||||
|
||||
// Load user manager
|
||||
await UserManager.boot();
|
||||
@ -70,7 +73,7 @@ export class Server
|
||||
* @param socket
|
||||
* @private
|
||||
*/
|
||||
private async handleConnection(socket: Socket) {
|
||||
private async handleConnection(socket: TSocket) {
|
||||
const eventsPath = path.join(__dirname, 'app', 'events');
|
||||
try {
|
||||
const files: string[] = await fs.promises.readdir(eventsPath);
|
||||
|
Reference in New Issue
Block a user