new Server(requestHandler)
Encapsulates a simple HTTP server for testing. The {@code onrequest} function should be overridden to define request handling behavior.
Parameters:
Name | Type | Description |
---|---|---|
requestHandler | function | The request handler for the server. |
- Source
Methods
address() → {Host}
- Source
Throws:
If the server is not running.
- Type
- Error
Returns:
This server's host info.
- Type:
- Host
host()
return {string} The host:port of this server.
- Source
Throws:
If the server is not running.
- Type
- Error
start(opt_portopt) → (non-null) {Promise.<Host>}
Starts the server on the given port. If no port, or 0, is provided, the server will be started on a random port.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
opt_port | number | <optional> | The port to start on. |
- Source
Returns:
A promise that will resolve with the server host when it has fully started.
- Type:
- Promise.<Host>
stop() → (non-null) {Promise}
Stops the server.
- Source
Returns:
A promise that will resolve when the server has closed all connections.
- Type:
- Promise
url(opt_pathnameopt) → {string}
Formats a URL for this server.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
opt_pathname | string | <optional> | The desired pathname on the server. |
- Source
Throws:
If the server is not running.
- Type
- Error
Returns:
The formatted URL.
- Type:
- string
Type Definitions
Host
Type:
- Object
- Source