initialize.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. export default function (context) {
  2. console.log("initialize.........");
  3. let proto = "https";
  4. let url = "";
  5. let cookies = "";
  6. // Server-side
  7. if (process.server) {
  8. console.log("server side............");
  9. const {
  10. req
  11. } = context;
  12. let host = req.headers.host;
  13. console.log("initialize...........req.............header");
  14. let proto = "https";
  15. if (req.headers[ "x-forwarded-proto" ]) {
  16. proto = req.headers[ "x-forwarded-proto" ];
  17. } else if (req.headers[ "x-scheme" ]) {
  18. proto = req.headers[ "x-scheme" ];
  19. } else if (host.indexOf("local.") != -1) {
  20. proto = "http";
  21. }
  22. url = proto + "://" + host;
  23. cookies = req.headers.cookie;
  24. console.log("server", req.headers)
  25. }
  26. // Client-side
  27. if (process.client) {
  28. console.log("client side............");
  29. url = document.location.href;
  30. let proto = "http";
  31. if (url.indexOf("https://") != -1) {
  32. proto = "https";
  33. }
  34. cookies = document.cookie;
  35. console.log("client", document.location)
  36. }
  37. let groups = {}
  38. try {
  39. let regx = new RegExp(
  40. "((?<branch>[a-z0-9_\\-]+)\\.)?(?<env>(www|prod|test|local|test-rooter|test-jishuin|prod-rooter|prod-jishuin|rooter|jishuin|app|test-kaifain|prod-kaifain|kaifain))\\.proginn\\.com(\\:(?<port>\\d+))?",
  41. "gim"
  42. );
  43. console.log(regx);
  44. console.log(url);
  45. groups = regx.exec(url).groups;
  46. } catch ( e ) {
  47. //失败默认设置为线上环境
  48. const { app } = context.app.$deviceType
  49. if (app) {
  50. groups = {
  51. env: "app"
  52. }
  53. } else {
  54. groups = {
  55. env: "www"
  56. }
  57. }
  58. }
  59. let api = "", jishuinUrl = "", rooterUrl = "", siteUrl = "", kaifainUrl = "", urlType = "";
  60. console.log(groups);
  61. if (groups) {
  62. let { branch, env, port } = groups;
  63. switch (env) {
  64. case "www":
  65. api = "https://www.proginn.com";
  66. siteUrl = "https://www.proginn.com";
  67. jishuinUrl = "https://jishuin.proginn.com";
  68. kaifainUrl = "https://kaifain.proginn.com";
  69. rooterUrl = "https://rooter.proginn.com";
  70. break;
  71. case "jishuin":
  72. !urlType && (urlType = 'jishuin')
  73. case "kaifain":
  74. !urlType && (urlType = 'kaifain')
  75. api = "https://jishuin.proginn.com";
  76. siteUrl = "https://www.proginn.com";
  77. jishuinUrl = "https://jishuin.proginn.com";
  78. kaifainUrl = "https://kaifain.proginn.com";
  79. rooterUrl = "https://rooter.proginn.com";
  80. break;
  81. case "app":
  82. !urlType && (urlType = 'app')
  83. api = "https://app.proginn.com";
  84. siteUrl = "https://app.proginn.com";
  85. jishuinUrl = "https://jishuin.proginn.com";
  86. kaifainUrl = "https://kaifain.proginn.com";
  87. rooterUrl = "https://rooter.proginn.com";
  88. break;
  89. case "test":
  90. !urlType && (urlType = 'www')
  91. case "test-jishuin":
  92. !urlType && (urlType = 'jishuin')
  93. case "test-rooter":
  94. !urlType && (urlType = 'rooter')
  95. case "test-kaifain":
  96. api = "https://" + branch + ".test.proginn.com";
  97. siteUrl = "https://" + branch + ".test.proginn.com";
  98. jishuinUrl = "https://" + branch + ".test-jishuin.proginn.com";
  99. kaifainUrl = "https://" + branch + ".test-kaifain.proginn.com";
  100. rooterUrl = "https://" + branch + ".test-rooter.proginn.com";
  101. !urlType && (urlType = 'kaifain')
  102. break;
  103. case "local":
  104. !urlType && (urlType = 'local')
  105. if (port && port != "80") {
  106. api = "http://local.proginn.com";
  107. siteUrl = "http://local.proginn.com:" + port;
  108. jishuinUrl = "http://jishuin.local.proginn.com";
  109. kaifainUrl = "http://kaifain.local.proginn.com";
  110. rooterUrl = "http://rooter.local.proginn.com";
  111. } else {
  112. api = "http://local.proginn.com";
  113. siteUrl = "http://local.proginn.com";
  114. jishuinUrl = "http://jishuin.local.proginn.com";
  115. kaifainUrl = "http://kaifain.local.proginn.com";
  116. rooterUrl = "http://rooter.local.proginn.com";
  117. }
  118. break;
  119. case "prod":
  120. !urlType && (urlType = 'www')
  121. case "prod-jishuin":
  122. !urlType && (urlType = 'jishuin')
  123. case "prod-rooter":
  124. !urlType && (urlType = 'rooter')
  125. case "prod-kaifain":
  126. !urlType && (urlType = 'kaifain')
  127. api = "https://" + branch + ".prod.proginn.com";
  128. siteUrl = "https://" + branch + ".prod.proginn.com";
  129. jishuinUrl = "https://" + branch + ".prod-jishuin.proginn.com";
  130. kaifainUrl = "https://" + branch + ".prod-kaifain.proginn.com";
  131. rooterUrl = "https://" + branch + ".prod-rooter.proginn.com";
  132. break;
  133. default:
  134. // 按生产处理
  135. !urlType && (urlType = 'www')
  136. api = "https://www.proginn.com";
  137. siteUrl = "https://www.proginn.com";
  138. jishuinUrl = "https://jishuin.proginn.com";
  139. kaifainUrl = "https://kaifain.proginn.com";
  140. rooterUrl = "https://rooter.proginn.com";
  141. break;
  142. }
  143. } else {
  144. // 按生产处理
  145. api = "https://www.proginn.com";
  146. siteUrl = "https://www.proginn.com";
  147. jishuinUrl = "https://jishuin.proginn.com";
  148. kaifainUrl = "https://kaifain.proginn.com";
  149. rooterUrl = "https://rooter.proginn.com";
  150. }
  151. context.store.commit("updateDomainConfig", {
  152. api, siteUrl, jishuinUrl, kaifainUrl, rooterUrl, urlType
  153. });
  154. context.store.commit("updateDeviceType", context.app.$deviceType || {});
  155. context.store.commit("updateIsPC", context.app.$deviceType.pc || false);
  156. context.store.commit("updateIsWeixin", context.app.$deviceType.wx || false);
  157. }