.env.domain.js 672 B

123456789101112131415161718192021222324252627282930
  1. const host = window.location.host
  2. const replaceQuotationMarks = (obj) => {
  3. if (Object.prototype.toString.call(obj) !== '[object Object]') {
  4. throw 'Please check you arguments...'
  5. }
  6. let result = {}
  7. for (let key in obj) {
  8. result[key] = obj[key].replace(/"/g, '')
  9. }
  10. return result
  11. }
  12. const test = replaceQuotationMarks(require('../../config/dev.env'))
  13. const master = replaceQuotationMarks(require('../../config/prod.env'))
  14. const domain = host.substring(0, host.indexOf('.')) || host.substring(0, host.indexOf(':'))
  15. let envDomain = {
  16. ...master
  17. }
  18. if (/^(0|192|localhost)|(test$)/.test(domain)) {
  19. envDomain = {
  20. ...test
  21. }
  22. }
  23. export {
  24. envDomain
  25. }