Class: Server

src/server~Server

new Server(optionsopt)

Constructs a server object that stores request handlers and delegates incoming requests to those handlers
Parameters:
Name Type Attributes Description
options Object <optional>
Options that should be passed to the internal server implementation
Source:

Methods

addProtoService(service, implementation)

Add a proto service to the server, with a corresponding implementation
Parameters:
Name Type Description
service Protobuf.Reflect.Service The proto service descriptor
implementation Object.<String, function()> Map of method names to method implementation for the provided service.
Source:

addService(service, implementation)

Add a service to the server, with a corresponding implementation. If you are generating this from a proto file, you should instead use addProtoService.
Parameters:
Name Type Description
service Object.<String, *> The service descriptor, as module:src/common.getProtobufServiceAttrs returns
implementation Object.<String, function()> Map of method names to method implementation for the provided service.
Source:

bind(port, credsopt)

Binds the server to the given port, with SSL enabled if creds is given
Parameters:
Name Type Attributes Description
port string The port that the server should bind on, in the format "address:port"
creds ServerCredentials <optional>
Server credential object to be used for SSL. Pass an insecure credentials object for an insecure port.
Source:

forceShutdown()

Forcibly shuts down the server. The server will stop receiving new calls and cancel all pending calls. When it returns, the server has shut down. This method is idempotent with itself and tryShutdown, and it will trigger any outstanding tryShutdown callbacks.
Source:

register(name, handler, serialize, deserialize, type) → {boolean}

Registers a handler to handle the named method. Fails if there already is a handler for the given method. Returns true on success
Parameters:
Name Type Description
name string The name of the method that the provided function should handle/respond to.
handler function Function that takes a stream of request values and returns a stream of response values
serialize function Serialization function for responses
deserialize function Deserialization function for requests
type string The streaming type of method that this handles
Source:
Returns:
True if the handler was set. False if a handler was already set for that name.
Type
boolean

start()

Start the server and begin handling requests
This:
Source:

tryShutdown(callback)

Gracefully shuts down the server. The server will stop receiving new calls, and any pending calls will complete. The callback will be called when all pending calls have completed and the server is fully shut down. This method is idempotent with itself and forceShutdown.
Parameters:
Name Type Description
callback function The shutdown complete callback
Source: