Manual Reference Source Test
public class | source

Routes

Class for setting up the Routes.

Test:

Constructor Summary

Public Constructor
public

constructor(PopApi: PopApi, options: Object)

Create a new Routes object.

Method Summary

Public Methods
public

Convert the thrown errors to an instance of ApiError.

public

Hook method for setting up middleware post setting up the routes.

public

Hook method for setting up middleware pre setting up the routes.

public

registerControllers(app: Express, PopApi: PopApi, controllers: Array<Object>): undefined

Register the controllers found in the controllers directory.

public

Remove security sensitive headers.

public

Error handler middleware

public

Catch the 404 errors.

public

setupRoutes(app: Express, PopApi: PopApi, controllers: Array<Object>): undefined

Setup the application service.

Public Constructors

public constructor(PopApi: PopApi, options: Object) source

Create a new Routes object.

Params:

NameTypeAttributeDescription
PopApi PopApi
  • nullable: false

The PopApi instance to bind the routes to.

options Object
  • nullable: false

The options for the routes.

options.app Express
  • nullable: false

The application instance to add middleware and bind the routes to.

options.controllers Array<Object>
  • nullable: true

The controllers to register.

Throw:

TypeError

'app' are required options for the routes middleware!

Test:

Public Methods

public convertErrors(err: Error, req: IncomingMessage, res: ServerResponse, next: Function): ApiError source

Convert the thrown errors to an instance of ApiError.

Params:

NameTypeAttributeDescription
err Error
  • nullable: false

The caught error.

req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

ApiError

The converted error.

Test:

public postRoutes(app: Express): undefined source

Hook method for setting up middleware post setting up the routes.

Params:

NameTypeAttributeDescription
app Express
  • nullable: false

The application instance to add middleware to.

Return:

undefined

Test:

public preRoutes(app: Express): undefined source

Hook method for setting up middleware pre setting up the routes.

Params:

NameTypeAttributeDescription
app Express
  • nullable: false

The application instance to add middleware to.

Return:

undefined

Test:

public registerControllers(app: Express, PopApi: PopApi, controllers: Array<Object>): undefined source

Register the controllers found in the controllers directory.

Params:

NameTypeAttributeDescription
app Express
  • nullable: false

The application instance to register the routers to.

PopApi PopApi
  • nullable: false

The PopApi instance to bind the routes to.

controllers Array<Object>
  • nullable: false

The controllers to register.

Return:

undefined

Test:

public removeServerHeader(req: IncomingMessage, res: ServerResponse, next: Function): undefined source

Remove security sensitive headers.

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

undefined

Test:

See:

public setErrorHandler(err: ApiError, req: IncomingMessage, res: ServerResponse, next: Function): Object source

Error handler middleware

Params:

NameTypeAttributeDescription
err ApiError
  • nullable: false

The caught error.

req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Object

The error object.

Test:

public setNotFoundHandler(req: IncomingMessage, res: ServerResponse, next: Function): ApiError source

Catch the 404 errors.

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

ApiError

A standard 404 error.

Test:

public setupRoutes(app: Express, PopApi: PopApi, controllers: Array<Object>): undefined source

Setup the application service.

Params:

NameTypeAttributeDescription
app Express
  • nullable: false

The application instance to add middleware and bind the routes to.

PopApi PopApi
  • nullable: false

The PopApi instance to bind the routes to.

controllers Array<Object>
  • optional
  • nullable: true

The controllers to register.

Return:

undefined

Test: