export const toSubdomain = (name: string): string =>
  name.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '')

export function buildAppUrl(appName: string, baseUrl: string): string {
  const url = new URL(baseUrl)
  url.hostname = `${toSubdomain(appName)}.${url.hostname}`
  return url.origin
}
