Preferences to customize the application.
The default settings for the configuration service. It's a
shortcuit for options.config.default
Protected
_configSince the configuration service has an async initialization, the class uses this flag internally to validate if the configuration has been initialized or not.
Protected
_controlledA list with all the top routes controlled by the application. Every time a controller is mounted, its route will be added here.
Protected
_expressThe Express application Jimpex uses under the hood.
Protected
Optional
_instanceThe instance of the server that is listening for requests.
Protected
_mountA list of functions that implement controllers and middlewares. When the application starts, the queue will be processed and those controllers and middlewares will be added to the server instance. The reason they are not added directly like with a regular Express implementation is that services on Jimple use lazy loading, and adding middlewares and controllers as they come could cause errors if they depend on services that are not yet registered.
Protected
_optionsThe customization settings for the application.
Protected
Optional
_serverA reference to the actuall HTTP the application will use. This can vary depending on
whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as
the express
property; if HTTPS is enabled, it will be an https
server; and if
HTTP2 is enabled, it will be an spdy
server.
Gets the events service.
The Express application Jimpex uses under the hood.
The server instance that gets created when the app is started.
The logger service.
The application customization options.
A list of the routes that have controllers mounted on them.
Protected
_addAdds a static folder to the application.
The route to add the folder to.
The path to the folder in the file system. If not defined, it will
be use the same value as route
. The path could be relative to the
project root, or where the application executable is located,
depending on the value of the onHome
parameter.
If true
, the path to the folder will be relative to the project
root. If false
, it will be relative to where the application
executable is located.
Protected
_configureThis helper method validates the path
options in order to register the app
location in the pathUtils
service. The app
location should be the path to where
the application executable is located, but due to how ESM works, we can't infer it
from the module
object, so we need either recieved as the appPath
setting, or try
to get it from the parent module.
Protected
_emitEmits an event using the events
service.
The literal name of the event, to type the event payload.
The name of the event to emit.
The event payload.
Protected
_initThis method is like a "lifecycle method", it gets executed on the constructor right
before the "boot step". The idea is for the method to be a helper when the
application is defined by subclassing Jimpex: the application could register
all important services here and the routes on boot, then, if the implementation needs
to access or overwrite a something, it can send boot: false
, access/register what
it needs, and then call boot()
. That would be impossible for an application without
overwriting the constructor and the boot functionality.
Protected
_initIt generates overwrites for the application options when it gets created. This method
is a helper for when the application is defined by subclassing Jimpex: It's
highly probable that if the application needs to change the default options, it would
want to do it right from the class, instead of having to do it on every
implementation. A way to do it would be overwriting the constructor and calling
super
with the custom overwrites, but this method exists so that won't be
necessary: when creating the options
, the constructor will merge the result of this
method on top of the default ones.
Protected
_loadLoads the contents of a dictionary of credentials files that need to be used to configure HTTPS.
The dictionary where the keys are the type of credentials
(ca
, cert
, key
) and the values are the paths to the
files.
If this is true
, the path of the files will be relative
to the project root. If it is false
, it will be relative
to where the application executable is located.
Protected
_loadESMModulesProtected
_mountProcesses the resources from the mount queue (added with Jimpex.mount and Jimpex.use), and adds them to the Express application.
Protected
_reduceSends a target object to a list of reducer events so they can modify or replace it.
The name of the event to use.
The object to reduce with the event.
Extra context for the listeners.
Protected
_setupSetups the configuration service. The new configuration service requires async calls
in order to load the configuration files (as it uses import
instead of require
),
so it can't be instantiated as the other services.
This method is called just before starting the application.
Protected
_setupProtected
_setupBased on the application options, it returns wheter the application is healthy or not.
This is an alias of start
. The idea is for it to be used on serverless platforms,
where you don't get to start your app, you just have export it.
Optional
port: numberIn case the configuration doesn't already have it,
this is the port where the application will use to run. If this
parameter is used, the method will overwrite the port
setting on the configuration service.
Optional
onStart: JimpexStartCallbackA callback function to be called when the server starts.
The server instance.
Mounts a route controller or a middleware into a server routes.
The route for the controller/middleware.
The controller/middleware resource to be mounted.
Adds a listener for an application event.
The name of the event, to match the type of the listener function.
The name of the event to listen for.
The listener function.
A function to unsubscribe the listener.
Adds a listener for an application event that will only be execuded once: the first time the event is triggered.
The name of the event, to match the type of the listener function.
The name of the event to listen for.
The listener function.
A function to unsubscribe the listener.
Starts the app server.
Optional
onStart: JimpexStartCallbackA callback function to be called when the server actually starts.
The server instance.
Adds a global middleware to the application.
The middleware resource to be added.
Jimpex is a mix of Jimple, a Javascript port of Pimple dependency injection container, and Express, one of the most popular web frameworks for Node.
Todo
Implement
helmet
.