title | layout | category |
---|---|---|
Kettle Servers |
default |
Kettle |
Kettle includes two builtin grades, kettle.server
for defining a plain HTTP server, and a derived
grade kettle.server.ws
for defining a server capable of handling WebSockets endpoints.
The former wraps the standard facilities of node.js for constructing an
http.Server
, and the latter wraps the facilities of the
ws WebSockets library for constructing a
ws.Server
. In both
cases, the Kettle grades can either accept servers previously constructed and injected in configuration, or can take
responsibility for constructing the native servers themselves (the default).
The kettle.server
grade accepts the following options which can usefully be configured by the user. Naturally by
virtue of being a fluid.component
there are numerous other parts of its lifecycle which can be customised, but these
are the options principally supported for user configuration:
Supported configurable options for a kettle.server | ||
---|---|---|
Option | Type | Description |
members.expressApp |
express |
The express application which this server is to be
bound to. If this option is not overriden, the server will automatically construct one using the
express() constructor.
|
members.httpServer |
http.Server |
The node.js
HTTP server which this server is to be bound to. If this option is not overriden,
the server will use the one extracted from the expressApp member
|
port |
Number |
The port number which this server is to listen on. Defaults to 8081. |
rootMiddleware |
middlewareSequence |
The group of middleware which is to be executed for every request handled by this server |
components.middlewareHolder |
Component |
A plain component container for middleware that is intended to be resolvable throughout the server's component tree |
events.onListen |
Event
|
An event fired once this server has started listening on its port. Fired with one argument, the server component itself |
events.beforeStop |
Event |
An event fired just before this server is about to be stopped. This is an opportunity to clean up any resource (e.g. close any open sockets). Fired with one argument, the server component itself |
events.onStopped |
Event |
An event fired after the server is stopped and the HTTP server is no longer listening. Fired with one argument, the server component itself |
events.onContributeMiddleware |
Event |
This event is useful for authors trying to integrate with 3rd-party express applications. This is a
useful lifecycle point, before Kettle registers its own middleware to the express application,
for an external integrator to register their own middleware first, e.g. using app.use .
Fired with one argument, the server component itself – typically only that.expressApp
will be of interest to the listener
|
events.onContributeRouteHandlers |
Event |
This event is useful for authors trying to integrate with 3rd-party express applications. This is a
useful lifecycle point, before Kettle registers its own route handlers to the express application,
for an external integrator to register their own route handlers first, e.g. using app.get
etc.. Fired with one argument, the server component itself – typically only that.expressApp
will be of interest to the listener
|
A WebSockets-capable server exposes all of the configurable options supported by a kettle.server
in addition to the
ones in the table below:
Supported configurable options for a kettle.server.ws | ||
---|---|---|
Option | Type | Description |
wsServerOptions |
Object |
Any options to be forwarded to the constructor of the
ws.Server .
Note that after construction, this server will be available as the top-level member named
wsServer on the overall component.
|