0.4.0 • Published 6 years ago

@jonathandelgado/server v0.4.0

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
6 years ago

server

Server library

addHealthItem(name, interval, func)

Add an item to be monitored for health

ParamTypeDescription
nameStringCannot already exist
intervalNumberMust be greater than or equal to zero
funcfunction() => Promise

addShutdownItem(name, priority, func)

Add a function to be run before the server completes a shutdown

ParamTypeDescription
nameString!_.isDefined(shutdownname)
priorityNumber>= 0 && <= 100
funcfunction() => Promise

setHealthItem(name, isHealthy)

Sets the health of a health item

ParamTypeDescription
nameStringMust exist
isHealthyBoolean

handleShutdown(err)

Run the shutdown procedure

ParamTypeDescription
errErrorError that caused the shutdown

createSocket(args) => Object

Creates a web socket server

ParamTypeDefault
argsObject
args.logBooleantrue
args.msgpackBooleanfalse
args.portNumber

createWeb(args) => Object

Creates a web server

ParamTypeDefaultDescription
argsObject
args.authByKeyBoolean | Stringfalsefalse disables
args.cookiesBooleanfalse
args.corsBooleanDefaults to args.isApi
args.etagBooleanDefaults to !args.isApi
args.gzipBooleantrue
args.httpNumber
args.httpsNumber
args.isApiBooleantrue
args.keepAliveBooleantrue
args.limitString1mb
args.logBooleantrue
args.middlewareArray.<function()>
args.noCacheBooleanDefaults to args.isApi
args.noFrameBooleanfalse
args.routesStringdist/routesfalse disables
args.staticBoolean | Stringdist/staticfalse disables
args.throttleBoolean | Objectfalsefalse disables
args.throttle.maxNumber60
args.throttle.ttlNumber60000
args.throttle.whitelistArray.<String>
args.timeoutNumber30000
args.tokenNameBoolean | Stringtoken
args.upstreamBooleanfalse
args.viewsStringviews

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.

ParamType
connConnection

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.