IModelHost

A backend must call IModelHost.startup before using any of the classes in imodeljs-backend. IModelHost initializes imodeljs-backend and captures backend configuration.

A backend may need to set IModelHostConfiguration.briefcaseCacheDir based on deployment parameters

A backend may need to set IModelHostConfiguration.appAssetsDir to identify its own assets directory. This would be needed, for example, if the app needs to import ECSchemas that it delivers.

Example:

  public static startupIModelHost() {
    // The host configuration.
    // The defaults will work for most backends.
    // Here is an example of how the briefcasesCacheDir property of the host configuration
    // could be set from an environment variable, which could be set by a cloud deployment mechanism.
    let briefcaseCacheDir = process.env.MY_SERVICE_BRIEFCASES_DIR;
    if (briefcaseCacheDir === undefined) {
      const tempDir = process.env.MY_SERVICE_TMP_DIR || KnownLocations.tmpdir;
      briefcaseCacheDir = path.join(tempDir, "iModelJs_cache");
    }

    const imHostConfig = new IModelHostConfiguration();
    imHostConfig.briefcaseCacheDir = briefcaseCacheDir;

    // Start up IModelHost, supplying the configuration.
    IModelHost.startup(imHostConfig);
  }

Last Updated: 13 June, 2024