const host = window.location.host

const replaceQuotationMarks = (obj) => {
  if (Object.prototype.toString.call(obj) !== '[object Object]') {
    throw 'Please check you arguments...'
  }
  let result = {}
  for (let key in obj) {
    result[key] = obj[key].replace(/"/g, '')
  }
  return result
}

const test = replaceQuotationMarks(require('../../config/dev.env'))
const master = replaceQuotationMarks(require('../../config/prod.env'))

const domain = host.substring(0, host.indexOf('.')) || host.substring(0, host.indexOf(':'))

let envDomain = {
  ...master
}
if (/^(0|192|localhost)|(test$)/.test(domain)) {
  envDomain = {
    ...test
  }
}

export {
  envDomain
}
