The options to construct the class.
Protected
Readonly
_eventsThe application envent bus, to listen and get the list of "controlled routes" after the application is started.
Protected
_fileWhether or not the file is ready to be served. In case the middleware uses an HTMLGenerator service, the file needs to be generated before being available, and that's why this flag exists.
Protected
Readonly
_getHTMLGeneratorA function to get a possible HTMLGenerator. This is injected as a "getter" to not interrupt the DIC "lifecycle": middlewares are initialized right when the app starts, and injecting a reference would force the service to be initialized too, even if a request is not being made.
Protected
_optionsThe customization options for the middleware.
Protected
_routeA list of regular expression that match the routes controlled by the application.
This is in case the useAppRoutes
option is set to true
; when the application gets
started, an event listener will obtain all the top controlled routes, create regular
expressions, and save them on this property.
Protected
Readonly
_sendThe service that serves a file.
The customization options.
Protected
_sendProtected
_setupProtected
_shouldGenerates the middleware that serves the HTML file.
It's common for an app to show an HTML view when no route was able to handle a request, so the idea behind this middleware is to avoid going to every middleware and controller and just specify that if the request is not for a route handled by a controller, just serve the HTML and avoid processing unnecessary data.
A simple example: The app has a route
/backend
that a frontend uses to get information. This middleware can be used to only allow the execution of middlewares and controllers when the request route is for/backend
.Disclaimer: Managing statics files with Express is not a best practice, but there are scenarios where there is not other choice.
Prettierignore