Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Application

Hierarchy

  • Application

Index

Constructors

constructor

  • Application object that handle the main working process of the project

    Parameters

    • options: AppOptions = {}

      Options of the Application

      const app = new Application({
              public: '/public',
              port: 3000,
              db: { ...dbParameters },
              waitForModuleInit: true
      })
      
      app.registerModule(...)
      app.registerModule(...)
      ...
      
      try {
              app.run()
      } catch(error) {
              // Error handling on promise catch
              console.log(error)
      }
      

    Returns Application

Properties

Protected Readonly _app

_app: Application

Express application

Protected Optional _db

_db: __module

Application database instance

Protected _dbConnectionPromise

_dbConnectionPromise: Promise<__module>

Database asynchronous connection promise

Protected _endpoints

_endpoints: EndpointList

Registered endpoints

Protected Readonly _io

_io: Server<DefaultEventsMap, DefaultEventsMap>

SocketIO server

Protected _modules

_modules: Module[]

Registered modules

Protected Readonly _options

_options: AppOptions

Protected Readonly _port

_port: number

Protected Readonly _public

_public: string

Protected Readonly _server

_server: Server

HTTP server from express

Protected _sockets

_sockets: Socket<DefaultEventsMap, DefaultEventsMap>[]

Connected sockets

Accessors

db

  • get db(): __module

sockets

  • get sockets(): Socket<DefaultEventsMap, DefaultEventsMap>[]

Methods

Private connectDatabase

  • connectDatabase(options: { dbname?: string; pass?: string; url: string; user?: string }): Promise<__module>
  • Try to connect to the mongo database

    Parameters

    • options: { dbname?: string; pass?: string; url: string; user?: string }

      Credentials

      • Optional dbname?: string

        Database name

      • Optional pass?: string

        Database user's password

      • url: string

        Database access url

      • Optional user?: string

        Database access user

    Returns Promise<__module>

    Mongoose instance

    const db = await connectDatabase({ ...dbOptions })
    

Private ensureModulesInit

  • ensureModulesInit(): Promise<any[]>
  • Returns Promise<any[]>

    The Promises results of the init methods of all modules that have the wait flag at true

    const modulesInitResponses = await ensureModulesInit()
    

getEndpoint

  • Fetch the endpoint matching the path and type

    Parameters

    • path: string

      Path to match

    • type: EndpointType

      Endpoint type to match

    Returns Endpoint

    The endpoint if one is found, otherwise null

    const userSocketEndpoint = getEndpoint('/userLogin', 'Socket')
    const userHTTPEndpoint = getEndpoint('/userLogin', 'HTTP')
    

Private handleSocketRequest

  • handleSocketRequest(socket: Socket<DefaultEventsMap, DefaultEventsMap>, path: string, data: any): any
  • Find the good handler and use it for the incoming request

    Parameters

    • socket: Socket<DefaultEventsMap, DefaultEventsMap>

      Socket to handle the request from

    • path: string

      Path of the request

    • data: any

      Data transmitted by the socket

    Returns any

    Whatever the handler returns

    socket.on('request', (data) => {
            const res = handleSocketRequest(socket, data.path, data)
    })
    

Private listenSocketRequests

  • listenSocketRequests(socket: Socket<DefaultEventsMap, DefaultEventsMap>): any
  • Listen to requests from the socket to redirect them

    Parameters

    • socket: Socket<DefaultEventsMap, DefaultEventsMap>

      Socket to listen to the requests from

    Returns any

    Whatever the handler returns

    io.on('connection', (socket) => {
            listenSocketRequests(socket)
    })
    

Private onSocketJoin

  • onSocketJoin(socket: Socket<DefaultEventsMap, DefaultEventsMap>): void
  • Spread client socket connection information

    Parameters

    • socket: Socket<DefaultEventsMap, DefaultEventsMap>

      Client socket

      io.on('connection', (socket) => {
              onSocketJoin(socket)
      })
      

    Returns void

registerModule

  • Instantiate and link a module to the Application

    Parameters

    • moduleClass: Constructor<Module>

      Class of the module to register

    • options: ModuleRegisteringOptions = {}

    Returns Promise<Module>

    The instance of the module

    const module = await registerModule(MyModuleClass, { wait: true })
    

run

  • run(): Promise<Server>
  • Start the server

    see

    Application.constructor

    Returns Promise<Server>

    The instance of the HTTP server

Generated using TypeDoc