Server

new Server(requestHandler)

Encapsulates a simple HTTP server for testing. The {@code onrequest} function should be overridden to define request handling behavior.

Parameters:
NameTypeDescription
requestHandlerfunction

The request handler for the server.

Methods

address() → {Host}

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.

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:
NameTypeAttributesDescription
opt_portnumber<optional>

The port to start on.

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.

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:
NameTypeAttributesDescription
opt_pathnamestring<optional>

The desired pathname on the server.

Throws:

If the server is not running.

Type
Error
Returns:

The formatted URL.

Type: 
string

Type Definitions

Host

Type:
  • Object