Member Junction
    Preparing search index...

    Discovers, initializes, and manages the lifecycle of server extensions.

    Called by MJServer's serve() function during startup. The loader reads the serverExtensions array from mj.config.cjs, uses MJ's ClassFactory to find registered extension classes, and calls Initialize() on each.

    1. Reads serverExtensions[] array from mj.config.cjs
    2. For each enabled entry, uses ClassFactory.CreateInstance(BaseServerExtension, driverClass)
    3. Creates an instance and calls Initialize(app, config)
    4. Tracks all loaded extensions for health checks and shutdown
    import { ServerExtensionLoader } from '@memberjunction/server-extensions-core';

    const loader = new ServerExtensionLoader();
    await loader.LoadExtensions(app, configInfo.serverExtensions);

    // Health check
    const health = await loader.HealthCheckAll();

    // Graceful shutdown
    await loader.ShutdownAll();
    Index

    Constructors

    Accessors

    • get ExtensionCount(): number

      Get the number of currently loaded extensions.

      Returns number

    • get Extensions(): readonly {
          DriverClass: string;
          Instance: BaseServerExtension;
      }[]

      Get all loaded extension instances for inspection or testing.

      Returns readonly { DriverClass: string; Instance: BaseServerExtension }[]

      Read-only array of loaded extensions with their driver class names.

    Methods

    • Run health checks on all loaded extensions.

      Each extension's HealthCheck() is called independently. If one extension's health check throws, it is reported as unhealthy without affecting others.

      Returns Promise<ExtensionHealthResult[]>

      Array of health results, one per loaded extension.

    • Load and initialize all enabled extensions from config.

      Extensions that fail to initialize are logged and skipped — they do not prevent other extensions from loading. This ensures one broken extension doesn't take down the entire server.

      Parameters

      • app: Application

        Express application for route registration.

      • extensionConfigs: ServerExtensionConfig[]

        Array of extension configs from mj.config.cjs.

      Returns Promise<void>

    • Shut down all loaded extensions gracefully.

      Called during MJServer's shutdown sequence (SIGTERM/SIGINT). Extensions are shut down in reverse order of loading. Errors during shutdown are logged but do not prevent other extensions from shutting down.

      Returns Promise<void>