@alicloud/console-base-conf-parse-env 1.4.9 → 1.4.10-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = getCountry;
7
+ var _cookie = require("@alicloud/cookie");
8
+ function getCountry() {
9
+ return (0, _cookie.getCookie)('apsara_country') || (0, _cookie.getCookie)('aliyun_country') || 'CN'; // CN INTL JP
10
+ }
@@ -21,16 +21,15 @@ function isCommonBuyPre() {
21
21
  function getEnv() {
22
22
  var _ref = window,
23
23
  _ref$location = _ref.location,
24
- protocol = _ref$location.protocol,
25
24
  hostname = _ref$location.hostname,
26
25
  port = _ref$location.port;
27
26
 
28
27
  /**
29
28
  * 本地开发:
30
- *
29
+ *
31
30
  * 1. 带端口的一般都是本地开发(但也有本地搭 nginx 后可以不带端口的)
32
31
  * 2. 再判断 host(如果再绑域名就只能认为不是本地)
33
- *
32
+ *
34
33
  * 注意:本地开发的情况,如果绑了日常的域名,不鸟之
35
34
  */
36
35
  if (port || /^127(?:\.0\.0)?\.1$|^0\.0\.0\.0$|^localhost$/.test(hostname)) {
@@ -39,7 +38,7 @@ function getEnv() {
39
38
 
40
39
  /**
41
40
  * 日常环境:
42
- *
41
+ *
43
42
  * 1. OneConsole 的输出
44
43
  * 2. URL 以 `.test` 结尾
45
44
  * 3. hostname 中带 `daily-` 或 `-daily`
@@ -50,13 +49,12 @@ function getEnv() {
50
49
 
51
50
  /*
52
51
  * 预发环境:
53
- *
52
+ *
54
53
  * 1. OneConsole 的输出
55
54
  * 2. CommonBuy 的输出
56
55
  * 2. hostname 中带 `pre-` 或 `-pre`
57
- * 3. 非 HTTPS (通常绑 host)的一般认为是预发
58
56
  */
59
- if (_consoleOneConfig.default.ONE && _consoleOneConfig.default.ENV === 'pre' || isCommonBuyPre() || /pre-|-pre/i.test(hostname) || protocol === 'http:') {
57
+ if (_consoleOneConfig.default.ONE && _consoleOneConfig.default.ENV === 'pre' || isCommonBuyPre() || /pre-|-pre/i.test(hostname)) {
60
58
  return _enum.EEnv.PRE;
61
59
  }
62
60
  return _enum.EEnv.PROD;
@@ -11,6 +11,7 @@ var _enum = require("../enum");
11
11
  var _getEnv = _interopRequireDefault(require("./get-env"));
12
12
  var _getSite = _interopRequireDefault(require("./get-site"));
13
13
  var _getChannel = _interopRequireDefault(require("./get-channel"));
14
+ var _getCountry = _interopRequireDefault(require("./get-country"));
14
15
  /**
15
16
  * 从浏览器、location、cookie 中获得到的静态数据,跟环境、站点、用户有关,项目的运行期间不可能变
16
17
  */
@@ -83,6 +84,9 @@ function parseEnv() {
83
84
  if (CHANNEL === 'EA134') {
84
85
  MAIN_RESOURCE_CDN = 'idptcloud01cdn.com';
85
86
  }
87
+
88
+ // 获取当前页面的国家
89
+ var COUNTRY = (0, _getCountry.default)();
86
90
  return {
87
91
  ENV: ENV,
88
92
  ENV_IS_DEV: ENV_IS_DEV,
@@ -97,6 +101,7 @@ function parseEnv() {
97
101
  FECS_HOST: FECS_HOST,
98
102
  FECS_URL_BASE: FECS_URL_BASE,
99
103
  MAIN_DOMAIN: MAIN_DOMAIN,
100
- MAIN_RESOURCE_CDN: MAIN_RESOURCE_CDN
104
+ MAIN_RESOURCE_CDN: MAIN_RESOURCE_CDN,
105
+ COUNTRY: COUNTRY
101
106
  };
102
107
  }
@@ -0,0 +1,4 @@
1
+ import { getCookie } from '@alicloud/cookie';
2
+ export default function getCountry() {
3
+ return getCookie('apsara_country') || getCookie('aliyun_country') || 'CN'; // CN INTL JP
4
+ }
@@ -14,16 +14,15 @@ function isCommonBuyPre() {
14
14
  export default function getEnv() {
15
15
  var _ref = window,
16
16
  _ref$location = _ref.location,
17
- protocol = _ref$location.protocol,
18
17
  hostname = _ref$location.hostname,
19
18
  port = _ref$location.port;
20
19
 
21
20
  /**
22
21
  * 本地开发:
23
- *
22
+ *
24
23
  * 1. 带端口的一般都是本地开发(但也有本地搭 nginx 后可以不带端口的)
25
24
  * 2. 再判断 host(如果再绑域名就只能认为不是本地)
26
- *
25
+ *
27
26
  * 注意:本地开发的情况,如果绑了日常的域名,不鸟之
28
27
  */
29
28
  if (port || /^127(?:\.0\.0)?\.1$|^0\.0\.0\.0$|^localhost$/.test(hostname)) {
@@ -32,7 +31,7 @@ export default function getEnv() {
32
31
 
33
32
  /**
34
33
  * 日常环境:
35
- *
34
+ *
36
35
  * 1. OneConsole 的输出
37
36
  * 2. URL 以 `.test` 结尾
38
37
  * 3. hostname 中带 `daily-` 或 `-daily`
@@ -43,13 +42,12 @@ export default function getEnv() {
43
42
 
44
43
  /*
45
44
  * 预发环境:
46
- *
45
+ *
47
46
  * 1. OneConsole 的输出
48
47
  * 2. CommonBuy 的输出
49
48
  * 2. hostname 中带 `pre-` 或 `-pre`
50
- * 3. 非 HTTPS (通常绑 host)的一般认为是预发
51
49
  */
52
- if (ONE_CONF.ONE && ONE_CONF.ENV === 'pre' || isCommonBuyPre() || /pre-|-pre/i.test(hostname) || protocol === 'http:') {
50
+ if (ONE_CONF.ONE && ONE_CONF.ENV === 'pre' || isCommonBuyPre() || /pre-|-pre/i.test(hostname)) {
53
51
  return EEnv.PRE;
54
52
  }
55
53
  return EEnv.PROD;
@@ -4,6 +4,7 @@ import { EEnv } from '../enum';
4
4
  import getEnv from './get-env';
5
5
  import getSite from './get-site';
6
6
  import getChannel from './get-channel';
7
+ import getCountry from './get-country';
7
8
 
8
9
  /**
9
10
  * 从浏览器、location、cookie 中获得到的静态数据,跟环境、站点、用户有关,项目的运行期间不可能变
@@ -77,6 +78,9 @@ export default function parseEnv() {
77
78
  if (CHANNEL === 'EA134') {
78
79
  MAIN_RESOURCE_CDN = 'idptcloud01cdn.com';
79
80
  }
81
+
82
+ // 获取当前页面的国家
83
+ var COUNTRY = getCountry();
80
84
  return {
81
85
  ENV: ENV,
82
86
  ENV_IS_DEV: ENV_IS_DEV,
@@ -91,6 +95,7 @@ export default function parseEnv() {
91
95
  FECS_HOST: FECS_HOST,
92
96
  FECS_URL_BASE: FECS_URL_BASE,
93
97
  MAIN_DOMAIN: MAIN_DOMAIN,
94
- MAIN_RESOURCE_CDN: MAIN_RESOURCE_CDN
98
+ MAIN_RESOURCE_CDN: MAIN_RESOURCE_CDN,
99
+ COUNTRY: COUNTRY
95
100
  };
96
101
  }
@@ -46,4 +46,5 @@ export interface IConfEnv {
46
46
  FECS_URL_BASE: string;
47
47
  MAIN_DOMAIN: string;
48
48
  MAIN_RESOURCE_CDN: string;
49
+ COUNTRY: string;
49
50
  }
@@ -0,0 +1,2 @@
1
+ import { IConfEnv } from '../types';
2
+ export default function getCountry(): IConfEnv['COUNTRY'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/console-base-conf-parse-env",
3
- "version": "1.4.9",
3
+ "version": "1.4.10-beta.0",
4
4
  "description": "ConsoleBase CONF.ENV parse",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,