Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Server

Create a new ActionHero Server. The required properties of an server. These can be defined statically (this.name) or as methods which return a value.

Hierarchy

Index

Constructors

constructor

Properties

attributes

attributes: object

attributes of the server

Type declaration

  • [key: string]: any

canChat

canChat: boolean

Can connections of this server use the chat system?

Optional config

config: ServerConfig

Shorthand for api.config.servers[this.type]

connectionCustomMethods

connectionCustomMethods: object

Methods descibed by the server to apply to each connection (like connection.setHeader for web connections)

Type declaration

  • [key: string]: Function

Optional goodbye

goodbye: Function

An optional message to send to clients when they disconnect

logConnections

logConnections: boolean

Should we log every new connection?

logExits

logExits: boolean

Should we log when a connection disconnects/exits?

Optional options

options: object

Type declaration

  • [key: string]: any

sendWelcomeMessage

sendWelcomeMessage: boolean

Should every new connection of this server type recieve the wecome message (defiend in locales, actionhero.welcomeMessage)

Optional server

server: any

A place to store the actuall server object you create

type

type: string

The name & type of the server.

Optional verbs

verbs: Array<string>

What connection verbs can connections of this type use?

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

buildConnection

  • buildConnection(data: any): Promise<void>
    • Build a the ActionHero.Connection from the raw parts provided by the server.
      this.buildConnection({
      rawConnection: {
      req: req,
      res: res,
      params: {},
      method: method,
      cookies: cookies,
      responseHeaders: responseHeaders,
      responseHttpCode: responseHttpCode,
      parsedURL: parsedURL
      },
      id: fingerprint + '-' + uuid.v4(),
      fingerprint: fingerprint,
      remoteAddress: remoteIP,
      remotePort: remotePort
      })

    Parameters

    • data: any

    Returns Promise<void>

connections

defaultAttributes

  • defaultAttributes(): object
  • Returns object

    • canChat: boolean
    • logConnections: boolean
    • logExits: boolean
    • sendWelcomeMessage: boolean
    • type: null
    • verbs: undefined[]

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

Abstract initialize

  • initialize(): Promise<void>
  • Method run as part of the initialize lifecycle of your server. Ususally configures the server.

    Returns Promise<void>

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

log

  • log(message: string, severity?: string, data?: any): void
  • Log a message from this server type. A wrapper around log() with a server prefix.

    Parameters

    • message: string
    • Optional severity: string
    • Optional data: any

    Returns void

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

processAction

  • processAction(connection: Connection): Promise<void>
  • When a connection has called an Action command, and all properties are set. Connection should have params.action set at least. on(event: 'actionComplete', cb: (data: object) => void): this;

    Parameters

    Returns Promise<void>

processFile

  • processFile(connection: Connection): Promise<void>
  • When a connection has called an File command, and all properties are set. Connection should have params.file set at least. Will eventuall call ActionHero.Server#sendFile.

    Parameters

    Returns Promise<void>

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Abstract sendFile

  • sendFile(connection: Connection, error: Error, fileStream: any, mime: string, length: number, lastModified: Date): Promise<void>
  • Must be defined explaining how to send a file to an induvidual connection. Might be a noop for some connection types.

    Parameters

    • connection: Connection
    • error: Error
    • fileStream: any
    • mime: string
    • length: number
    • lastModified: Date

    Returns Promise<void>

Abstract sendMessage

  • sendMessage(connection: Connection, message: string | object | Array<any>, messageId?: string): Promise<void>
  • Must be defined explaining how to send a message to an induvidual connection.

    Parameters

    • connection: Connection
    • message: string | object | Array<any>
    • Optional messageId: string

    Returns Promise<void>

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Abstract start

  • start(): Promise<void>
  • Method run as part of the start lifecycle of your server. Ususally boots the server (listens on port, etc).

    Returns Promise<void>

Abstract stop

  • stop(): Promise<void>
  • Method run as part of the stop lifecycle of your server. Ususally configures the server (disconnects from port, etc).

    Returns Promise<void>

validate

  • validate(): void

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc