new Server(requestHandler)
Encapsulates a simple HTTP server for testing. The {@code onrequest} function should be overridden to define request handling behavior.
| Name | Type | Description |
|---|---|---|
requestHandler | function | The request handler for the server. |
- Source
Methods
address() → {Host}
- Source
If the server is not running.
- Type
- Error
This server's host info.
- Type:
- Host
host()
return {string} The host:port of this server.
- Source
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
opt_port | number | <optional> | The port to start on. |
- Source
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
A promise that will resolve when the server has closed all connections.
- Type:
- Promise
url(opt_pathnameopt) → {string}
Formats a URL for this server.
| Name | Type | Attributes | Description |
|---|---|---|---|
opt_pathname | string | <optional> | The desired pathname on the server. |
- Source
If the server is not running.
- Type
- Error
The formatted URL.
- Type:
- string
Type Definitions
Host
- Object
- Source