Skip to content

Add ability to consume multiple config files #2

Description

@armingjazi

One of Web Docker's drawbacks is its reliance on a stitched config file, which requires a server function to stitch the uploaded config files. However, in many cases, users should avoid incurring the cost of additional infrastructure. In this scenario, Web Docker should be capable of stitching the files together without relying on a server function.

Proposed API:

export type WebDockerOptions = {
  configFilePath?: string;
  configPaths?: string[];
  logEvents?: boolean;
  scope?: string;
};

const webDocker = new Webdocker({
    configPaths: ["https://folder/path1", "https://folder/path2"]
});

Possible implementation:

class RemoteConfigurationService {
  private readonly configFilePath: string | undefined = undefined;
  private readonly configPaths: string[] | undefined = undefined;

  constructor(options: WebDockerOptions) {
    if (!options.configFilePath && !options.configPaths) {
      throw Error ("No Config path was defined");
    } else if (options.configFilePath) {
      this.configFilePath = options.configFilePath;
    } else {
       this.configPaths = options.configPaths;      
    }
  }

    async fetch(): Promise<Config[] | undefined> {
    if (this.configFilePath) {
      return this.fetchConfigurations(this.configFilePath);
    }
    if (this.configPaths) {
      return this.fetchAllConfigurations(this.configPaths);
    }
  }
  
  private async fetchAllConfigurations(configPath: string[]): Config[] { 
     const configs = [] 
     for (const configPath of configPaths) {
         const data = await fetch(configFilePath);        
         configs.push(await data.json());
     }
     return configs;
  }
}```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions