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

  • EventEmitter
    • Server

Index

Constructors

constructor

Properties

attributes

attributes: {}

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: {}

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

Type declaration

  • [key: string]: Function

logConnections

logConnections: boolean

Should we log every new connection?

logExits

logExits: boolean

Should we log when a connection disconnects/exits?

Optional options

options: {}

Type declaration

  • [key: string]: any

sendWelcomeMessage

sendWelcomeMessage: boolean

Should every new connection of this server type receive the welcome message (defined in locales, actionhero.welcomeMessage)

Optional server

server: any

A place to store the actually server object you create

type

type: string

The name & type of the server.

Optional verbs

verbs: string[]

What connection verbs can connections of this type use?

Static Readonly captureRejectionSymbol

captureRejectionSymbol: typeof captureRejectionSymbol

Static captureRejections

captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): Server
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Server

buildConnection

  • buildConnection(data: {}): 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: {}
      • [key: string]: any

    Returns Promise<void>

connections

defaultAttributes

  • defaultAttributes(): { canChat: boolean; logConnections: boolean; logExits: boolean; sendWelcomeMessage: boolean; type: any; verbs: any[] }
  • Returns { canChat: boolean; logConnections: boolean; logExits: boolean; sendWelcomeMessage: boolean; type: any; verbs: any[] }

    • canChat: boolean
    • logConnections: boolean
    • logExits: boolean
    • sendWelcomeMessage: boolean
    • type: any
    • verbs: any[]

emit

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

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

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

getMaxListeners

  • getMaxListeners(): number
  • Returns number

Optional goodbye

Abstract initialize

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

    Returns Promise<void>

listenerCount

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

    • event: 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: (...args: any[]) => void): Server
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Server

on

  • on(event: string | symbol, listener: (...args: any[]) => void): Server
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Server

once

  • once(event: string | symbol, listener: (...args: any[]) => void): Server
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Server

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): Server
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Server

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): Server
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Server

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 eventually 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): Server
  • Parameters

    • Optional event: string | symbol

    Returns Server

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): Server
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Server

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 individual 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 | any[], messageId?: string): Promise<void>
  • Must be defined explaining how to send a message to an individual connection.

    Parameters

    • connection: Connection
    • message: string | object | any[]
    • Optional messageId: string

    Returns Promise<void>

setMaxListeners

  • setMaxListeners(n: number): Server
  • Parameters

    • n: number

    Returns Server

Abstract start

  • start(): Promise<void>
  • Method run as part of the start lifecycle of your server. Usually 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. Usually configures the server (disconnects from port, etc).

    Returns Promise<void>

validate

  • validate(): void

Static getEventListener

  • getEventListener(emitter: EventEmitter | DOMEventTarget, name: string | symbol): Function[]
  • Returns a list listener for a specific emitter event name.

    Parameters

    • emitter: EventEmitter | DOMEventTarget
    • name: string | symbol

    Returns Function[]

Static listenerCount

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

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static on

  • on(emitter: EventEmitter, event: string, options?: StaticEventEmitterOptions): AsyncIterableIterator<any>
  • Parameters

    • emitter: EventEmitter
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns AsyncIterableIterator<any>

Static once

  • once(emitter: NodeEventTarget, event: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string, options?: StaticEventEmitterOptions): Promise<any[]>
  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns Promise<any[]>

Generated using TypeDoc