ServerUtils

server. ServerUtils

Server-related utilities

Constructor

new ServerUtils()

Source:

Methods

(static) addErrorHandler(next)

Source:
Adds extra properties to the request object to allow for easy translations
Parameters:
Name Type Description
next function

(static) addExistenceProps(req, res, next)

Source:
Adds extra properties to the request object to allow for easy existence checking of common request objects
Example
"IMPORTANT NOTE: body data is completely ignored for GET requests, any code
requiring it should switch to use POST."

let req = { 'params': { 'foo':'bar' }, 'query': {}, 'body': {} };
req.hasParams // true
req.hasQuery // false
req.hasBody // false
Parameters:
Name Type Description
req external:ExpressRequest
res external:ExpressResponse
next function

(static) apiNotFoundHandler(req, res, next)

Source:
Middleware for handling 404 errors on the API router
Parameters:
Name Type Description
req external:ExpressRequest
res external:ExpressResponse
next function

(static) cacheRouteConfig(routeConfig) → {function}

Source:
Caches the route config on the incoming request
Parameters:
Name Type Description
routeConfig Route
Returns:
Type
function

(async, static) debugRequestTime(req, res, next)

Source:
Adds logs for debugging each request time
Parameters:
Name Type Description
req external:ExpressRequest
res external:ExpressResponse
next function

(static) generateRouterMap(topRouter) → {Object}

Source:
Generates a map for a given router
Parameters:
Name Type Description
topRouter Router
Returns:
The route map
Type
Object

(static) genericErrorHandler(error, req, res, next)

Source:
Generic error handling middleware for the API router
Parameters:
Name Type Description
error Error
req external:ExpressRequest
res external:ExpressResponse
next function

(async, static) handleInternalRoutes(req, res, next)

Source:
Handles restriction of routes marked as internal
Parameters:
Name Type Description
req external:ExpressRequest
res external:ExpressResponse
next function

(static) mapHandler(topRouter) → {function}

Source:
Handler for returning an API map
Parameters:
Name Type Description
topRouter Router
Returns:
Middleware function
Type
function

(static) rootNotFoundHandler(req, res)

Source:
Middleware for handling 404 errors on the root router
Parameters:
Name Type Description
req external:ExpressRequest
res external:ExpressResponse