Skip to main content

Class: WebServer

@divine/web-service.WebServer

A web server that listens for incoming HTTP requests on a specific port and delegates requests to one or more WebService instances.

Constructors

constructor

new WebServer(host, port, defaultService)

Parameters

NameType
hoststring
portnumber
defaultServiceWebService<any>

Defined in

web-service/src/server.ts:33

Properties

host

Readonly host: string

Defined in

web-service/src/server.ts:33


port

Readonly port: number

Defined in

web-service/src/server.ts:33


server

Readonly server: Server

The underlying Node.js Server instance.

Defined in

web-service/src/server.ts:27

Accessors

addressInfo

get addressInfo(): AddressInfo

Information about the actual listening port, as provided by the Node.js Server.

Returns

AddressInfo

Defined in

web-service/src/server.ts:158

Methods

mount

mount(mountPoint, service): WebServer

Mounts/adds a secondary WebService at a specific path.

By default, all requests are routed to the default WebService which was provided when the constructor was invoced, but it's possible to mount additional WebService instances as well, forming a multi-application server. In this case, the default WebService could be used for only a landing/front page and global error handlers for missing pages.

Parameters

NameTypeDescription
mountPointstringThe path prefix where the service should be available. Must both begin and end with a forward slash.
serviceWebService<any>The WebService to mount.

Returns

WebServer

Defined in

web-service/src/server.ts:67


start

start(startOptions?): Promise<WebServer>

Starts the WebServer.

Registers signal handlers (unless stopSignals is false) for automatic shutdown, and then starts listening on the configured port.

If waitForStop is true, wait is automatically invoked and this method will thus not return until the server is stopped in that case.

Parameters

NameTypeDescription
startOptions?StartOptionsStart-up options.

Returns

Promise<WebServer>

This WebServer.

Defined in

web-service/src/server.ts:103


stop

stop(): Promise<WebServer>

Stops the WebServer and returns when the server is fully stopped.

Returns

Promise<WebServer>

This WebServer.

Defined in

web-service/src/server.ts:133


unmount

unmount(serviceOrMountPoint): WebServer

Unmounts/removes a secondary WebService.

Parameters

NameTypeDescription
serviceOrMountPointstring | WebService<any>Either a WebService.

Returns

WebServer

Defined in

web-service/src/server.ts:79


wait

wait(): Promise<WebServer>

Waits until the WebServer is stopped.

This method waits for stop to be called, either manually or indirectly by one of the signals that was registered during the start method.

Returns

Promise<WebServer>

This WebServer.

Defined in

web-service/src/server.ts:149