RoutingUnit

libflitter/routing/RoutingUnit~ RoutingUnit

The routing unit loads route definitions from a specific directory and registers them as Express routers with the underlying Express app. This system requires a specific object structure in the route definition file and currently supports route prefixing, GET routes, and POST routes.

Constructor

new RoutingUnit(router_directoryopt)

Source:

Instantiate the unit. Resolves the path to the router directory.

Parameters:
Name Type Attributes Default Description
router_directory string <optional>
'./app/routing/routers'

the path to the router directory

Extends

  • libflitter/Unit~Unit

Methods

directories() → {Object}

Source:

Get the directories provided by this unit. module:libflitter/routing/RoutingUnit~RoutingUnit#directory as "routers"

Returns:
Type
Object

(async) go(app, context) → {Promise.<void>}

Source:

Loads the unit. For each route definition file in module:libflitter/routing/RoutingUnit~RoutingUnit#directory, create an Express router and register it with the underlying Express app. Also, bind a helper function for redirecting the user to the appropriate contexts. Router files are discovered recursively.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

context module:libflitter/Context~Context

the Unit's context

Returns:
Type
Promise.<void>

name() → {string}

Source:

Get the name of the unit.

Returns:

"routing"

Type
string

redirect(to) → {function}

Source:

A helper function that returns Express middleware to redirect the request to the specified destination.

Parameters:
Name Type Description
to string

destination route to which the request should be redirected

Returns:
  • Express middleware
Type
function

templates() → {Object}

Source:

Get the templates provided by this unit. Currently, this is the "router" template generated by module:libflitter/templates/router.

Returns:
Type
Object