Application
The application receives requests and dispatches them to all middleware. It provides error handling and logging.
Instantiate an Application
, configure it by registering your server(s) and middleware.
constructor
Create a ChatAlly application that dispatches incoming chat requests from all registered servers to all registered middleware.
use
: Register a Middleware or a Server
Middlewares are executed in order of registration, but can await next()
to wait for the following middlewares to finish. It is preferrable to use a named function over an arrow function, because the name is used to identify child loggers. Optionally, you can provide a name for the middleware.
This method returns this
, so you can chain calls to it.
dispatch
: Dispatch request and response to all middlewares
This method is registered as event handler on the servers’ “dispatch” event. It decouples handling of incoming messages from the event loop and returns immediately. Register the “write” or “finished” events on the response, if you are interested in the result.
The order is the order of registration. Middleware exceptions are dispatched to the context. This method throws only, if the context throws.
listen
: Start all registered servers in parallel
getLogger
: Get a child logger
Events
The application is a node.js EventEmitter and emits the following event in case of an error.
I.e., as listener you will receive the error (potentially with some extra data) and the context (without the next()
method).