MiddlewareUnit

libflitter/middleware/MiddlewareUnit~ MiddlewareUnit

The middleware unit is responsible for parsing and loading middleware defined in the specified directory. It then stores it such that it can be accessed using the global mw() function.

Constructor

new MiddlewareUnit(mw_pathopt, global_definitions_fileopt)

Source:

Instantiate the unit. Resolves the paths to th middleware directory and the global middleware list.

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

path to the directory containing the middleware definition files

global_definitions_file string <optional>
'./app/routing/Middleware.js'

path to the file containing a list of middleware to be applied to all routes

Extends

Methods

(async) cleanup(app) → {Promise.<void>}

Source:
Inherited From:

Cleans up the unit's resources before Flitter closes.

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

the Flitter app

Returns:
Type
Promise.<void>

directories() → {Object}

Source:
Overrides:

Get the directories provided by this unit. module:libflitter/middleware/MiddlewareUnit~MiddlewareUnit#directory as "middleware".

Returns:
Type
Object

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

Source:
Overrides:

Loads the unit. For each middleware definition file in module:libflitter/middleware/MiddlewareUnit~MiddlewareUnit#directory, store it in an object by its Flitter canonical name. Then, bind the daemon and helper functions to the appropriate contexts.

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>

mw(name) → {function}

Source:

A helper function to return the Express middleware function for a registered middleware, using its Flitter canonical name. This is usually bound to the module:libflitter/app/FlitterApp~FlitterApp context.

Parameters:
Name Type Description
name string

the Flitter canonical name of the middleware whose handler should be returned

Returns:
  • the Express middleware
Type
function

name() → {string}

Source:
Overrides:

Get the name of the unit.

Returns:

"middleware"

Type
string

templates() → {Object}

Source:

Get the templates provided by this unit. Currently, "middleware" template, using the generator module:libflitter/templates/middleware.

Returns:
Type
Object