Constructor Summary
Public Constructor | ||
public |
constructor(PopApi: PopApi, options: Object) Create a new Routes object. |
Method Summary
Public Methods | ||
public |
convertErrors(err: Error, req: IncomingMessage, res: ServerResponse, next: Function): ApiError Convert the thrown errors to an instance of ApiError. |
|
public |
postRoutes(app: Express): undefined Hook method for setting up middleware post setting up the routes. |
|
public |
Hook method for setting up middleware pre setting up the routes. |
|
public |
Register the controllers found in the controllers directory. |
|
public |
removeServerHeader(req: IncomingMessage, res: ServerResponse, next: Function): undefined Remove security sensitive headers. |
|
public |
setErrorHandler(err: ApiError, req: IncomingMessage, res: ServerResponse, next: Function): Object Error handler middleware |
|
public |
setNotFoundHandler(req: IncomingMessage, res: ServerResponse, next: Function): ApiError Catch the 404 errors. |
|
public |
Setup the application service. |
Public Constructors
public constructor(PopApi: PopApi, options: Object) source
Create a new Routes object.
Params:
Name | Type | Attribute | Description |
PopApi | PopApi |
|
The PopApi instance to bind the routes to. |
options | Object |
|
The options for the routes. |
options.app | Express |
|
The application instance to add middleware and bind the routes to. |
options.controllers | Array<Object> |
|
The controllers to register. |
Throw:
'app' are required options for the routes middleware! |
Public Methods
public convertErrors(err: Error, req: IncomingMessage, res: ServerResponse, next: Function): ApiError source
Convert the thrown errors to an instance of ApiError.
Params:
Name | Type | Attribute | Description |
err | Error |
|
The caught error. |
req | IncomingMessage |
|
The incoming message request object. |
res | ServerResponse |
|
The server response object. |
next | Function |
|
The next function to move to the next middleware. |
public postRoutes(app: Express): undefined source
Hook method for setting up middleware post setting up the routes.
Params:
Name | Type | Attribute | Description |
app | Express |
|
The application instance to add middleware to. |
public preRoutes(app: Express): undefined source
Hook method for setting up middleware pre setting up the routes.
Params:
Name | Type | Attribute | Description |
app | Express |
|
The application instance to add middleware to. |
public registerControllers(app: Express, PopApi: PopApi, controllers: Array<Object>): undefined source
Register the controllers found in the controllers directory.
public removeServerHeader(req: IncomingMessage, res: ServerResponse, next: Function): undefined source
Remove security sensitive headers.
Params:
Name | Type | Attribute | Description |
req | IncomingMessage |
|
The incoming message request object. |
res | ServerResponse |
|
The server response object. |
next | Function |
|
The next function to move to the next middleware. |
public setErrorHandler(err: ApiError, req: IncomingMessage, res: ServerResponse, next: Function): Object source
Error handler middleware
Params:
Name | Type | Attribute | Description |
err | ApiError |
|
The caught error. |
req | IncomingMessage |
|
The incoming message request object. |
res | ServerResponse |
|
The server response object. |
next | Function |
|
The next function to move to the next middleware. |
public setNotFoundHandler(req: IncomingMessage, res: ServerResponse, next: Function): ApiError source
Catch the 404 errors.
Params:
Name | Type | Attribute | Description |
req | IncomingMessage |
|
The incoming message request object. |
res | ServerResponse |
|
The server response object. |
next | Function |
|
The next function to move to the next middleware. |