AppInterface

appManager
readonly
Type:
AppManager
config
readonly

see affiliated bi-config npm package

Type:
Config
name
readonly
Type:
String
resourceManager
readonly
service
readonly
Type:
Service
status
readonly

one of AppStatus enum

Type:
String
new AppInterface(appManager, config, options)
abstract
Parameters:
  • config
    • Type: Config
    • module

  • options
    • Type: Object
      • name
        • Type: String
        • app's name

      • validator optional
        • Type: Object
        • Ajv validator initialization options

          • schemas optional
            • Type: Object or Array
            • list of globally accessible schema definitions

Fires:
buildRouter(options)Router
Parameters:
  • options
    • Type: Object
      • public optional
        • Type: String
      • version optional
        • Type: String
      • url
        • Type: String
Returns: Router
close()Promise

shutdown underlying net socket. if not running, resolved Promise will be returned

Returns: Promise
getRoute(uid)Route
Parameters:
  • uid
    • Type: String
Throws:
  • Error - when route is not found

Returns: Route
getValidator()Ajv
Returns: Ajv validator instance
listen(port|socket)
abstract
Parameters:
  • port|socket optional
    • Type: Integer or String
on(event, callback)Boolean

registeres event listener.
overrides event emmiter implementation

Parameters:
  • event
    • Type: String
  • callback
    • Type: function
Returns: Boolean
use(endpoint, callback)AppInterface
abstract

bind application-level middleware that will be run before Route's middleware stack

Parameters:
  • endpoint optional
    • Type: String
  • callback optional
    • Type: function
Returns: AppInterface
  • self
build-router

emitted with each AppInterface#buildRouter method call.

Properties:
error

fires each time an unexpected internal Error is encoutered. When the Error is catched in the application space, the Error is coerced to ServiceError type which is safe to respond with.

Internal listener is binded at initialization time which logs all received Errors with the bi-logger package.
AppInterface#status is updated with the first internal error setting the Application to error state.

Properties:
  • error
    • Type: Error
error-response

By default an App handles all "expected" & unexpected Errors automatically and responds to a request accordingly.
By pushing a listener to this event, you can define custom user error processing logic and respond to the request manually.
Listeners of this event are executed asynchronously - Promises are supported.

Properties:
  • res
    • Type: http.ServerResponse
    • response

Example:
app.on('error-response', function(err, res) {
    //pseudocode:
    //renders html view and sends html response instead of default json response
    return res.render('error', err); //returns a Promise
});
listening

reflects http[s] server listening event

Properties:
post-build

emitted after app route definitions are assembled into a single function and binded to internal http[s] server.

Properties:
post-init

emitted after internal initialization of the App instance. At this point the App instance should be fully initiallized.

Properties:
pre-build

emitted before app route definitions are assembled into a single function.

Properties:
pre-init

emitted before internal initialization of the App instance

Properties:
status-changed

emitted once each time after status change. Once you get AppStatus#ERROR status, the App's status can NOT be changed thus no more status-changed events will be emitted.

Properties:
  • status
    • Type: String
    • see AppStatus enum for available option values

unknown-error

Is emitted before a response to a request is sent and allows to convert an unknown error (an error which is not instanceof RequestError and at the same time is not dirrect instanceof Error) to RequestError which will be then processed in place of the original unknown error object.
if no listener is present all unknown errors will be automatically converted to ServiceError

Properties:
  • err
    • Type: Error
  • errorHandler
    • Type: function
    • callback function

Example:
app.on('unknown-error', function(err, errorHandler) {
    if (err instanceof SequelizeUniqueConstraintError) {
        return errorHandler(new RequestError('Entity already exists'));
    }
    //hand back the error processing to the application
    return errorHandler(err);
});
comments powered by Disqus