Home Manual Reference Source Test Repository
import {Application} from '@cedx/koa-core/src/application.js'
public class | source

Application

Extends:

koa~Koa → Application

Represents an application providing functionalities specific to Web requests.

Test:

Static Member Summary

Static Public Members
public static get

The default address that the application is listening on.

public static get

The default port that the application is listening on.

Constructor Summary

Public Constructor
public

constructor(rootPath: string)

Initializes a new instance of the class.

Member Summary

Public Members
public

[key]: *

public get

The address that the application is listening on.

public get

The base path of the application files.

public set

basePath(value: string): *

Sets the base path of the application files.

public get

The directory that contains the controller classes.

public set

controllerPath(value: string): *

Sets the directory that contains the controller classes.

public get

Value indicating whether the application runs in debug mode.

public get

Value indicating whether the application must use a secure connection.

public get

Value indicating whether the application is currently listening.

public get

mailer: Mailer

The mailer application component.

public get

The application name.

public

Custom application parameters.

public get

The port that the application is listening on.

public get

The Web root directory that contains the static files.

public set

publicPath(value: string): *

Sets the Web root directory that contains the static files.

public get

The directory that stores runtime files.

public set

runtimePath(value: string): *

Sets the directory that stores runtime files.

public get

The version number of this application.

public get

The directory that contains the view files.

public set

viewPath(value: string): *

Sets the directory that contains the view files.

Method Summary

Public Methods
public

async close(): Promise

Stops the application from accepting new connections.

public

async end(status: number)

Terminates the application.

public

get(id: string, throwError: boolean): *

Gets the component instance with the specified identifier.

public

Gets a value indicating whether the application has instantiated the component with the specified identifier.

public

init(config: object)

Initializes the application.

public

async listen(port: number, address: string): Promise<number>

Begin accepting connections.

public

remove(id: string)

Removes the component instance with the specified identifier.

public

async run(options: object): Promise

Runs the application.

public

set(id: string, value: *)

Registers a component instance with this application.

Static Public Members

public static get DEFAULT_ADDRESS: string source

The default address that the application is listening on.

public static get DEFAULT_PORT: number source

The default port that the application is listening on.

Public Constructors

public constructor(rootPath: string) source

Initializes a new instance of the class.

Params:

NameTypeAttributeDescription
rootPath string
  • optional

The root directory of the application package. Defaults to the current working directory.

Public Members

public [key]: * source

public get address: string source

The address that the application is listening on.

Test:

public get basePath: string source

The base path of the application files.

public set basePath(value: string): * source

Sets the base path of the application files.

public get controllerPath: string source

The directory that contains the controller classes.

public set controllerPath(value: string): * source

Sets the directory that contains the controller classes.

public get debug: boolean source

Value indicating whether the application runs in debug mode.

Test:

public get forceSSL: boolean source

Value indicating whether the application must use a secure connection.

public get listening: boolean source

Value indicating whether the application is currently listening.

Test:

public get mailer: Mailer source

The mailer application component.

public get name: string source

The application name.

Test:

public params: object source

Custom application parameters.

public get port: number source

The port that the application is listening on.

Test:

public get publicPath: string source

The Web root directory that contains the static files.

public set publicPath(value: string): * source

Sets the Web root directory that contains the static files.

public get runtimePath: string source

The directory that stores runtime files.

public set runtimePath(value: string): * source

Sets the directory that stores runtime files.

public get version: string source

The version number of this application.

public get viewPath: string source

The directory that contains the view files.

public set viewPath(value: string): * source

Sets the directory that contains the view files.

Public Methods

public async close(): Promise source

Stops the application from accepting new connections. It does nothing if the application is already closed.

Return:

Promise

Completes when the application is finally closed.

Emit:

*

The "close" event.

public async end(status: number) source

Terminates the application. This method replaces the process.exit() method by ensuring the application life cycle is completed before terminating the application.

Params:

NameTypeAttributeDescription
status number
  • optional

The exit status (value 0 means normal exit while other values mean abnormal exit).

Emit:

*

The "end" event.

public get(id: string, throwError: boolean): * source

Gets the component instance with the specified identifier.

Params:

NameTypeAttributeDescription
id string

The component identifier.

throwError boolean
  • optional

Value indicating whether to throw an error if the specified identifier is not registered before.

Return:

*

The component of the specified identifier, or a null reference if component identifier is not previously registered.

Throw:

TypeError

The specified identifier refers to a nonexistent component while throwError is true.

public has(id: string): boolean source

Gets a value indicating whether the application has instantiated the component with the specified identifier.

Params:

NameTypeAttributeDescription
id string

The component identifier.

Return:

boolean

true if the application has instantiated the component, otherwise false.

public init(config: object) source

Initializes the application.

Params:

NameTypeAttributeDescription
config object
  • optional

An object specifying the application configuration.

public async listen(port: number, address: string): Promise<number> source

Begin accepting connections. It does nothing if the application is already started.

Params:

NameTypeAttributeDescription
port number
  • optional

The port that the application should run on.

address string
  • optional

The address that the application should run on.

Return:

Promise<number>

The port that the application is running on.

Emit:

*

The "listening" event.

public remove(id: string) source

Removes the component instance with the specified identifier.

Params:

NameTypeAttributeDescription
id string

The component identifier.

public async run(options: object): Promise source

Runs the application.

Params:

NameTypeAttributeDescription
options object
  • optional

An object specifying the application settings.

Return:

Promise

Completes when the application has been started.

Emit:

*

The "begin" event.

Throw:

Error

The application is already started.

public set(id: string, value: *) source

Registers a component instance with this application.

Params:

NameTypeAttributeDescription
id string

The component identifier.

value *

The component instance to be registered.