jimpex
    Preparing search index...

    Class Jimpex

    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.

    Implement helmet.

    Hierarchy

    • Jimple
      • Jimpex
    Index

    Constructors

    Properties

    _configReady: boolean = false

    Since the configuration service has an async initialization, the class uses this flag internally to validate if the configuration has been initialized or not.

    _controlledRoutes: string[] = []

    A list with all the top routes controlled by the application. Every time a controller is mounted, its route will be added here.

    _express: Express

    The Express application Jimpex uses under the hood.

    The instance of the server that is listening for requests.

    _mountQueue: ((server: Express) => void)[] = []

    A 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.

    _options: JimpexOptions

    The customization settings for the application.

    _server?: JimpexServer

    A reference to the actual 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.

    Accessors

    • get express(): Express

      The Express application Jimpex uses under the hood.

      Returns Express

    • get routes(): string[]

      A list of the routes that have controllers mounted on them.

      Returns string[]

    Methods

    • Adds a static folder to the application.

      Parameters

      • route: string

        The route to add the folder to.

      • folder: string = ''

        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.

      • onHome: boolean = false

        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.

      Returns void

    • This 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 received as the appPath setting, or try to get it from the parent module.

      Returns void

      If the method should use the path from the parent module, but can't find it.

    • This 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 sub-classing 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.

      Returns void

    • It generates overwrites for the application options when it gets created. This method is a helper for when the application is defined by sub-classing 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.

      Returns DeepPartial<JimpexOptions>

    • Loads the contents of a dictionary of credentials files that need to be used to configure HTTPS.

      Parameters

      • credentialsInfo: JimpexHTTPSCredentials

        The dictionary where the keys are the type of credentials (ca, cert, key) and the values are the paths to the files.

      • onHome: boolean = true

        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.

      Returns Promise<JimpexHTTPSCredentials>

    • Loads the ESM modules that are needed by Jimpex. This is called just before the starting the application so they'll be available for all the services.

      Returns Promise<void>

    • Setups 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.

      Returns Promise<void>

    • Registers the "core services" on the container: logger, events, utils, etc.

      Returns void

    • Configures the Express application based on the class options.

      Returns void

    • This is where the app would register all its specific services, middlewares and controllers.

      Returns void

    • Disables the server TLS validation. Meant to be used for development purposes.

      Returns void

    • Returns SimpleConfig

    • Type Parameters

      • T = unknown

      Parameters

      • setting: string | string[]
      • OptionalasArray: boolean

      Returns T

    • 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.

      Parameters

      • Optionalport: number

        In 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.

      • OptionalonStart: JimpexStartCallback

        A callback function to be called when the server starts.

      Returns Promise<JimpexServerInstance>

      The server instance.

    • Mounts a route controller or a middleware into a server routes.

      Parameters

      • route: string

        The route for the controller/middleware.

      • controller: ControllerLike

        The controller/middleware resource to be mounted.

      Returns void