server
- Description:
- HTTP server functionality using Express.js
- Source:
Classes
- Router
- ServerModule
- ServerUtils
Methods
(static) exports.addExistenceProps(req, res, next)
- Description:
- Adds extra properties to the request object to allow for easy existence checking of common request objects
- Source:
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) exports.cacheRouteConfig(routeConfig) → {function}
- Description:
- Caches the route config on the incoming request
- Source:
Parameters:
| Name |
Type |
Description |
routeConfig |
Route
|
|
Returns:
-
Type
-
function
(static) exports.generateRouterMap(topRouter) → {Object}
- Description:
- Generates a map for a given router
- Source:
Parameters:
| Name |
Type |
Description |
topRouter |
Router
|
|
Returns:
The route map
-
Type
-
Object
(static) exports.getAllRoutes(router) → {Map.<string, Set.<string>>}
- Description:
- Collects all registered routes with their methods across the router hierarchy
- Source:
Parameters:
| Name |
Type |
Description |
router |
Router
|
The router to traverse |
Returns:
Map of route paths to sets of allowed methods
-
Type
-
Map.<string, Set.<string>>
(static) exports.loadRouteConfig(rootDir, target, optionsopt) → {Promise.<(Object|null)>}
- Description:
- Reads and processes a routes.json file from a module's root directory,
validating against the app's jsonschema module and resolving handler strings against a target object.
- Source:
Parameters:
| Name |
Type |
Attributes |
Description |
rootDir |
String
|
|
Path to the module root (where routes.json lives) |
target |
Object
|
|
The object to resolve handler strings against |
options |
Object
|
<optional>
|
Optional configuration
Properties
| Name |
Type |
Attributes |
Description |
schema |
String
|
<optional>
|
Schema name to validate against (defaults to 'routes') |
handlerAliases |
Object
|
<optional>
|
Map of handler string aliases to pre-resolved functions |
defaults |
String
|
<optional>
|
Path to a default routes template JSON file. When provided and
routes.json is found, the template's routes are resolved and prepended to config.routes.
Custom routes with `override: true` are merged onto the matching default (by path) instead of
being appended as duplicates. |
|
Returns:
Parsed config with resolved handlers, or null if no routes.json
-
Type
-
Promise.<(Object|null)>
(static) exports.mapHandler(topRouter) → {function}
- Description:
- Handler for returning an API map
- Source:
Parameters:
| Name |
Type |
Description |
topRouter |
Router
|
|
Returns:
Middleware function
-
Type
-
function
(static) exports.registerRoutes(router, routes, auth)
- Description:
- Registers routes on a router and configures their permissions with auth.
- Source:
Parameters:
| Name |
Type |
Description |
router |
Router
|
The router to add routes to |
routes |
Array
|
Array of route definition objects |
auth |
Object
|
The auth module instance |
Type Definitions
Route
- Description:
- Defines how an individual API route should be handled
- Source:
Properties:
| Name |
Type |
Description |
route |
String
|
The name of the api (this will be used as the API endpoint) |
handlers |
Object
|
Object mapping HTTP methods to request handler functions. Note: Any HTTP methods not specified in `handlers` will not be exposed.
Properties
| Name |
Type |
Attributes |
Description |
post |
Array.<function()>
|
function
|
<optional>
|
POST handlers for the route |
get |
Array.<function()>
|
function
|
<optional>
|
GET handlers for the route |
put |
Array.<function()>
|
function
|
<optional>
|
PUT handlers for the route |
delete |
Array.<function()>
|
function
|
<optional>
|
DELETE handlers for the route |
|
Defines how an individual API route should be handled
Type:
Example
{
route: '/:id?',
handlers: {
// can be an array of middleware/handlers
post: [beforePost, handlePostRequest, afterPost],
// or an individual function
get: getRequest,
put: putRequest,
// or an in-line function
delete: (req, res, next) => { next(); }
}
}