Extends
Members
Type:
AppManager
see affiliated serviser-config
npm package
Type:
Config
Type:
String
Type:
ResourceManager
App specific Router constructor
Type:
function
Type:
Service
one of AppStatus
enum
Type:
String
Constructor
- appManager
- Type:
AppManager
- 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
orArray
list of globally accessible schema definitions
App is http
impementation of AppInterface
and represents
a bundle of Routers
with Routes
. It holds http[s] server object
or its equivalent/replacement and references to the AppManager
and Service
instances which it was created from. It also manages its own Config
instance with restricted scope
Parameters:
Fires:
Methods
- port
- Type:
Integer
orString
or socket
- hostname optional
- Type:
String
- backlog optional
- Type:
Integer
the maximum length of the queue of pending connections. The actual length will be determined by your OS through sysctl settings such as tcp_max_syn_backlog and somaxconn on linux. The default value of this parameter is 511 (not 512).
- options optional
- Type:
Object
- ssl optional
- Type:
Boolean
- Default:
false
- endpoint optional
- Type:
String
- callback optional
- Type:
function
String
returns protocol + host url string
Returns:String
start http(s) server listening on configured port
Parameters:
undefined
bind application-level middleware that will be run before Route
's
middleware stack
Parameters:
undefined
Inherited Methods
- options
- Type:
Object
- public optional
- Type:
String
- version optional
- Type:
String
- url
- Type:
String
- event
- Type:
String
- callback
- Type:
function
Router
Parameters:
Router
Promise
shutdown underlying net socket. if not running, resolved Promise will be returned
Returns:Promise
Route
Ajv
Ajv
validator instance
Boolean
registeres event listener.
overrides event emmiter implementation
Parameters:
Boolean
Events
- error
- Type:
Error
- err
- Type:
RequestError
- res
- Type:
http.ServerResponse
response
- app
- Type:
AppInterface
- app
- Type:
AppInterface
- app
- Type:
AppInterface
- app
- Type:
AppInterface
- status
- Type:
String
see
AppStatus
enum for available option values- err
- Type:
Error
- errorHandler
- Type:
function
callback function
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 serviser-logger package.
AppInterface#status
is updated with the first internal error setting the Application to error
state.
Properties:
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:
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
});
emitted after app route definitions are assembled into a single function and binded to internal http[s] server.
Properties:
emitted after internal initialization of the App instance and before
AppInterface#event:pre-build
and AppInterface#event:post-build
events.
This is the time to register application wide middlewares which get executed before
the main route implementation.
Properties:
emitted before app route definitions are assembled into a single function.
Properties:
emitted before internal initialization of the App instance which will validate configuration, setup default application wide response headers and error handling middlewares
Properties:
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:
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:
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);
});