import express , { Application , RequestHandler } from 'express' ; import Server from './typings/Server' ; import ChatServer from './typings/ChatServer' ; import Controller from './typings/Controller' ; import db from './models/index' ; import AuthController from './controllers/AuthController' ; import TokenController from './controllers/TokenController' ; import MatchmakingController from './controllers/MatchmakingController' ; import RoomController from './controllers/RoomController' ; import { json , urlencoded } from 'body-parser' ; import cors from 'cors' ; import { PORT } from "./config" ; import path from "path" ; const app = express ( ) ; const server = new Server ( app , db . sequelize , PORT ) ; const controllers = [ new AuthController ( ) , new TokenController ( ) , new MatchmakingController ( ) , new RoomController ( ) ] ; const globalMiddleware = [ urlencoded ( { extended : false } ) , json ( ) , cors ( { credentials : true , origin : true } ) , express . static ( path . join ( __dirname , '../client/build' ) ) ] ; Promise . resolve ( ) . then ( ( ) => server . initDatabase ( ) ) . then ( ( ) => { server . loadMiddleware ( globalMiddleware ) ; server . loadControllers ( controllers ) ; const httpServer = server . run ( ) ; server . renderClient ( ) ; const chatServer = new ChatServer ( httpServer ) ; chatServer . run ( ) ; } ) ;