Below is a breakdown of the Server
component which is an extended Router
instance for modularity support.
- See
> [Router]
for more information on additional methods and properties available.
key_file_name
[String
]: Path to SSL private key file to be used for SSL/TLS.- Example:
'misc/key.pm'
- [Required] for an SSL server.
- Example:
cert_file_name
[String
]: Path to SSL certificate file.- Example:
'misc/cert.pm'
- [Required] for an SSL server.
- Example:
passphrase
[String
]: Strong passphrase for SSL cryptographic purposes.- Example:
'SOME_RANDOM_PASSPHRASE'
- Optional for an SSL server.
- Example:
dh_params_file_name
[String
]: Path to SSL Diffie-Hellman parameters file.- Example:
'misc/dhparam4096.pm'
- Optional for an SSL server.
- Example:
ssl_prefer_low_memory_usage
[Boolean
]: Specifies uWebsockets to prefer lower memory usage while serving SSL requests.auto_close
[Boolean
]: Specifies whether theServer
instance should automatically be closed when process exits.- Default:
true
- Default:
fast_buffers
[Boolean
]: Specifies HyperExpress to useBuffer.allocUnsafe
for storing incoming request body data for faster performance.- Default:
false
- Note! Any data in the unsafely allocated buffer will always be written over thus this option is provided for those working with strict regulatory requirements.
- Default:
fast_abort
[Boolean
]: Specifies HyperExpress to forcefully/abruptly close incoming request connections with bad conditions such as payload too large. This can significantly improve performance but at the cost of no HTTP status code being received by the sender.- Default:
false
- Default:
trust_proxy
[Boolean
]: Specifies whether incoming request data from intermediate proxy(s) should be trusted.- Default:
false
- Default:
max_body_length
[Number
]: Maximum number ofbytes
allowed for incoming request body size. For reference, 1kb = 1000 Bytes and 1mb = 1000kb.- Default:
250 * 1000
or 250kb
- Default:
streaming
[Object
]: Specifies global constructor options for internal readable and writable streams.readable
[stream.ReadableOptions
]: Constructor options forRequest
body readable streams.- See the official
> [ReadableOptions]
Node.js documentation for more information.
- See the official
writable
[stream.WritableOptions
]: Constructor options forResponse
body writable streams.- See the official
> [WritableOptions]
Node.js documentation for more information.
- See the official
- Note you can also override globally specified
streaming
options on a per-route basis in the route options.
Property | Type | Description |
---|---|---|
locals |
Object |
Can be used to stores references local to this instance. |
uws_instance |
uWS |
Underlying uWebsockets TemplatedApp instance. |
routes |
Object |
All routes created on current instance. |
middlewares |
Object |
All non route specific midddlewares on current instance. |
handlers |
Object |
Global handlers for current instance. |
listen(Number: port, String?: host)
: Starts the uWebsockets server on specified port.- Returns a
Promise
and resolvesuw_listen_socket
. - Note port is required and host is
0.0.0.0
by default.
- Returns a
close(uws_socket?: socket)
: Closes the uWebsockets se@Brver gracefully.- Note: socket is not required.
set_error_handler(Function: handler)
: Binds a global catch-all error handler that will attempt to catch mostsynchronous/asynchronous errors.- Handler Parameters:
(Request: request, Response: response, Error: error) => {}
.
- Handler Parameters:
set_not_found_handler(Function: handler)
: Binds a global catch-all not found handler that will handle all requests which are not handled by any routes.- Handler Parameters:
(Request: request, Response: response) => {}
.
- Handler Parameters:
use(...2 Overloads)
: Binds middlewares and mountsRouter
instances on the optionally specified pattern hierarchy.- Overload Types:
use(Function | Router: ...handler)
: Binds the specified functions as middlewares and mounts theRouter
instances on the/
pattern.use(String: pattern, Function | Router: ...handler)
: Binds the specified functions as middlewares and mounts theRouter
instances on the specifiedpattern
hierarchy.
- Note
pattern
is treated as a wildcard match by default and does not support*
/:param
prefixes. - See
> [Router]
&> [Middlewares]
for full documentation on this method.
- Overload Types:
any(...4 Overloads)
: Creates an HTTP route on the specified pattern. Alias methods are listed below for all available HTTP methods.- Alias Methods:
get()
,post()
,put()
,delete()
,head()
,options()
,patch()
,trace()
,connect()
,upgrade()
,ws()
. - Overload Types:
any(String: pattern, Function: handler)
: Creates an any method HTTP route with the specifiedhandler
.any(String: pattern, Object: options, Function: handler)
: Creates an any method HTTP route with the specifiedoptions
andhandler
.any(String: pattern, Function: middleware, Function: handler)
: Creates an any method HTTP route with the specified route-specificmiddleware
andhandler
.any(String: pattern, Function[]: middlewares, Function: handler)
: Creates an any method HTTP route with the specified set of route-specificmiddlewares
andhandler
.
- See
> [Router]
for full documentation on this method. - See
> [Websocket]
for usage documentation on theupgrade()
andws()
alias method.
- Alias Methods:
publish(String: topic, String|Buffer|ArrayBuffer: message, Boolean?: is_binary, Boolean?: compress)
: Publishes the specified message to the specified topic in MQTT syntax to all WebSocket connections on this Server instance.