Constructor
new Router(root, parentRouter, routes)
- Description:
- If passing an ExpressRouter as the parentRouter, it is assumed that the Express Router is the top of the router 'heirarchy' (which will have an impact of some of the Router methods)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
root |
String | Route API endpoint for this router |
parentRouter |
Router | ExpressRouter | Parent to mount router |
routes |
Array.<Route> | Array of routes |
Members
childRouters :Array.<Router>
- Description:
- List of sub-routers
- Source:
List of sub-routers
Type:
- Array.<Router>
expressRouter :external:ExpressRouter
- Description:
- Express router instance
- Source:
Express router instance
Type:
- external:ExpressRouter
handlerMiddleware :Array.<function()>
- Description:
- Middleware stack to be added before route handlers (useful if you need access to specific request attributes that don't exist when standard middleware runs)
- Source:
Middleware stack to be added before route handlers (useful if you need access to specific request attributes that don't exist when standard middleware runs)
Type:
- Array.<function()>
map :Object
- Description:
- Returns the map of routes attached to this router
- Source:
Returns the map of routes attached to this router
Type:
- Object
parentRouter :ExpressApp|Router
- Description:
- Express router instance
- Source:
Express router instance
Type:
- ExpressApp | Router
path :String
- Description:
- Generates this router's path from its ancestors
- Source:
Generates this router's path from its ancestors
Type:
- String
root :String
- Description:
- The root route the router will be mounted at
- Source:
The root route the router will be mounted at
Type:
- String
routerMiddleware :Array.<function()>
- Description:
- Middleware stack to be added directly to the router
- Source:
Middleware stack to be added directly to the router
Type:
- Array.<function()>
routes :Array.<Route>
- Description:
- Routes config
- Source:
Routes config
Type:
- Array.<Route>
url
- Description:
- Returns the URL for the router
- Source:
Returns the URL for the router
Methods
addHandlerMiddleware(…func) → {AbstractApiModule}
- Description:
- Adds middleware to be called prior to any route handlers. Accepts multiple params. Useful if you need access to specific request attributes that don't exist when standard middleware runs.
- Source:
- See:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
func |
function |
<repeatable> |
Middleware function(s) to be added |
Returns:
This instance, for chaining
- Type
- AbstractApiModule
addMiddleware(…func) → {AbstractApiModule}
- Description:
- Adds middleware to the router stack. Accepts multiple params.
- Source:
- See:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
func |
function |
<repeatable> |
Middleware function(s) to be added |
Returns:
This instance, for chaining
- Type
- AbstractApiModule
addRoute(…route) → {AbstractApiModule}
- Description:
- Store route definition. Accepts multiple params.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
route |
Route |
<repeatable> |
Config of route(s) to be added |
Returns:
This instance, for chaining
- Type
- AbstractApiModule
createChildRouter(root, routes) → {Router}
- Description:
- Creates and adds a sub-router to this router.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
root |
string | The root of the child router |
routes |
Array.<Route> | Array of Routes to add |
Returns:
The new router instance
- Type
- Router
flattenRouters(router) → {Array}
- Description:
- Creates an array defining the router inheritance hierarchy
- Source:
Parameters:
Name | Type | Description |
---|---|---|
router |
Router | The root router |
Returns:
- Type
- Array
getHandlerMiddleware(router, middleware) → {Array.<function()>}
- Description:
- Recursively gets middleware of the current router heirarchy
- Source:
Parameters:
Name | Type | Description |
---|---|---|
router |
Router | The current router (used when run recursively) |
middleware |
Array.<function()> | Middleware function(s) (used when run recursively) |
Returns:
- Type
- Array.<function()>
init()
- Description:
- Initialises the API
- Source:
log(level, …args)
- Description:
- Logs a message
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
level |
String | Level of log | |
args |
* |
<repeatable> |
Arguments to be logged |
validateRoute(r) → {Boolean}
- Description:
- Function for filtering bad route configs
- Source:
Parameters:
Name | Type | Description |
---|---|---|
r |
Route | Route config |
Returns:
- Type
- Boolean
warnOnInited(message) → {Boolean}
- Description:
- Shortcut for checking Router has initialised, logging a warning if not
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message |
String | Message to log on error |
Returns:
- Type
- Boolean