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
Name | Type |
---|---|
host | string |
port | number |
defaultService | WebService <any > |
Defined in
Properties
host
• Readonly
host: string
Defined in
port
• Readonly
port: number
Defined in
server
• Readonly
server: Server
The underlying Node.js Server instance.
Defined in
Accessors
addressInfo
• get
addressInfo(): AddressInfo
Information about the actual listening port, as provided by the Node.js Server.
Returns
AddressInfo
Defined in
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
Name | Type | Description |
---|---|---|
mountPoint | string | The path prefix where the service should be available. Must both begin and end with a forward slash. |
service | WebService <any > | The WebService to mount. |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
startOptions? | StartOptions | Start-up options. |
Returns
Promise
<WebServer
>
This WebServer.
Defined in
stop
▸ stop(): Promise
<WebServer
>
Stops the WebServer and returns when the server is fully stopped.
Returns
Promise
<WebServer
>
This WebServer.
Defined in
unmount
▸ unmount(serviceOrMountPoint
): WebServer
Unmounts/removes a secondary WebService.
Parameters
Name | Type | Description |
---|---|---|
serviceOrMountPoint | string | WebService <any > | Either a WebService. |
Returns
Defined in
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.