import { HostConfig } from './host.config';

export abstract class UrlConfig {
  static getUrls<T extends any>(hotConfig: HostConfig, urls: T): T {
    const nUrls: any = {};
    for (const key in urls) {
      if (urls.hasOwnProperty(key)) {
        const pathname = urls[key];
        nUrls[key] = UrlConfig.getUrl(hotConfig, pathname);
      }
    }

    return nUrls;
  }

  private static getUrl(hotConfig: HostConfig, pathname: string): string {
    // const url = new URL(
    //   `${hotConfig.protocol}://${hotConfig.domain}:${String(hotConfig.port)}`
    // );
    // url.pathname = pathname;

    // return url.href;
    return `${hotConfig.protocol}://${hotConfig.domain}:${String(
      hotConfig.port
    )}${pathname}`;
  }
}
