@jonathandelgado/server v0.4.0
server
Server library
addHealthItem(name, interval, func)
Add an item to be monitored for health
| Param | Type | Description |
|---|---|---|
| name | String | Cannot already exist |
| interval | Number | Must be greater than or equal to zero |
| func | function | () => Promise |
addShutdownItem(name, priority, func)
Add a function to be run before the server completes a shutdown
| Param | Type | Description |
|---|---|---|
| name | String | !_.isDefined(shutdownname) |
| priority | Number | >= 0 && <= 100 |
| func | function | () => Promise |
setHealthItem(name, isHealthy)
Sets the health of a health item
| Param | Type | Description |
|---|---|---|
| name | String | Must exist |
| isHealthy | Boolean |
handleShutdown(err)
Run the shutdown procedure
| Param | Type | Description |
|---|---|---|
| err | Error | Error that caused the shutdown |
createSocket(args) => Object
Creates a web socket server
| Param | Type | Default |
|---|---|---|
| args | Object | |
| args.log | Boolean | true |
| args.msgpack | Boolean | false |
| args.port | Number |
createWeb(args) => Object
Creates a web server
| Param | Type | Default | Description |
|---|---|---|---|
| args | Object | ||
| args.authByKey | Boolean | String | false | false disables |
| args.cookies | Boolean | false | |
| args.cors | Boolean | Defaults to args.isApi | |
| args.etag | Boolean | Defaults to !args.isApi | |
| args.gzip | Boolean | true | |
| args.http | Number | ||
| args.https | Number | ||
| args.isApi | Boolean | true | |
| args.keepAlive | Boolean | true | |
| args.limit | String | 1mb | |
| args.log | Boolean | true | |
| args.middleware | Array.<function()> | ||
| args.noCache | Boolean | Defaults to args.isApi | |
| args.noFrame | Boolean | false | |
| args.routes | String | dist/routes | false disables |
| args.static | Boolean | String | dist/static | false disables |
| args.throttle | Boolean | Object | false | false disables |
| args.throttle.max | Number | 60 | |
| args.throttle.ttl | Number | 60000 | |
| args.throttle.whitelist | Array.<String> | ||
| args.timeout | Number | 30000 | |
| args.tokenName | Boolean | String | token | |
| args.upstream | Boolean | false | |
| args.views | String | views |
setupMsgpackConnection(conn)
Setup a connection for use with msgpack, emits message-decoded and adds a sendEncoded function to the connection. The protocol used has a leading variable before the message for the event type.
| Param | Type |
|---|---|
| conn | Connection |
SocketPool(messageHandler, isMsgpacked)
Creates a pool of sockets. To add a new connection to the pool, call pool.add(conn), connections will automatically be pruned as they disconnect. To manually empty the pool you can call pool.empty(). To send a message to all the connections in the pool, you can call pool.send(args). Depending on your initial configuration, sent and received messages may be handled using msgpack.