The Middleware Unit
MiddlewareUnit loads and registers middleware from the specified directory and applies global middleware. It makes the middleware globally available under the
constructor(String mw_path = './app/routing/middleware', String global_definitions_file = './app/routing/Middleware.js')
Initializes the class. Resolves the fully-qualified paths for the middleware definitions folder and the file which contains the array of middleware to be applied globally and stores these paths in
go(express app, function next)
Recursively iterates over files in
this.directory and loads the middleware definition classes from them and stores the collection by name in
_flit.middleware.definitions. Then, it creates an access function and stores it in
_flit.middleware.mw. Then, global middleware is loaded from the array in
this.globals_file and is applied, in order, to the underlying Express
app. This creates the
Middleware context and the
next function in the stack is called under it.
Object describing the services, templates, and directories provided by this unit. They are as follows:
||The name of the service. This is added to the
||The fully-qualified path of the middleware definition files. This is added to the
||Template that creates new middleware definition file in
Set on initialization. Specifies the fully-qualified path of the middleware definition files to be processed. Each of these files should export a class with a
test() function that runs the middleware. Each file's middleware is assigned a name based on the name of the file it was retrieved from. This includes sub-directories. As is convention in Flitter, sub-directories are delineated with a
: character. So a middleware class loaded from the file
auth/RequireAuth.middleware.js would be named
Set on initialization. Specifies the fully-qualified path of the global middleware file. This file should export an
Array of references to middleware that will be applied to every request Flitter handles. These should be specified using the global
This context provides access to registered middleware and the global middleware access function. It also guarantees that that all requests will have the global middleware applied to them.
Stores variables and functions provided by this context.
A key-value collection of defined middleware where keys are parsed from the names of files in the specified middleware directory, following the Flitter convention for sub-directory naming. The values are classes containing a
test() function that is applied as middleware.
Returns the middleware class from
_flit.middleware.definitions with the