Class: Server

Server

new Server(inPort, inDelegate)

Web and Websockets REST server for node. Listens for HTTP and WS requests and dispatches to REST handlers or files.
Parameters:
Name Type Description
inPort integer port number on which to listen
inDelegate object delegate to resolve REST requests
Source:

Methods

onHTTPRequest(inRequest, outResponse, inRequestURL, inRequestParams)

Called on receipt of an HTTP request. Calls the REST dispatcher to try and resolve the request against our delegate. If the resolution succeeds, the handler is called and the response assumed to be JSON. If the resolution fails, we attempt to serve a file with the appropriate path.
Parameters:
Name Type Description
inRequest object HTTP request
outResponse object HTTP response
inRequestURL object parsed URL
inRequestParams object parsed request parameters
Source:

onWSMessage(inMessage, inWebSocket)

Called on receipt of a WebSockets message. Calls the REST dispatcher to try and resolve the request against our delegate. If the resolution succeeds, the handler is called and the response assumed to be JSON. If the resolution fails, we attempt to serve a file with the appropriate path.
Parameters:
Name Type Description
inMessage object WebSockets message
inWebSocket object the WebSocket on which the message arrived
Source:

sendFile(inPathName, outResponse)

Send a file with the specified pathname to the specified response. Called when REST dispatch fails. If the file cannot be found or another error occurs, a 404 file not found response is sent.
Parameters:
Name Type Description
inPathName string path of file
outResponse object HTTP response
Source:

stop()

Stop serving requests.
Source: