@alicloud/alfa-core 1.5.5 → 1.5.6-alpha.1
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.
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
var _window$ALIYUN_CONSOL;
|
|
2
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
|
|
4
|
+
// 支持的主权云 CDN Host
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
var whiteList = ['idptcloud01cdn.com', ((_window$ALIYUN_CONSOL = window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.MAIN_RESOURCE_CDN) || 'alicdn.com'];
|
|
4
7
|
var win = window;
|
|
5
8
|
|
|
6
9
|
// 兼容非公有云环境
|
|
@@ -11,9 +14,14 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
|
|
|
11
14
|
if (win.__alfa_cdn_host__) {
|
|
12
15
|
return win.__alfa_cdn_host__;
|
|
13
16
|
}
|
|
17
|
+
var scriptUrl = (_document$currentScri = document.currentScript) === null || _document$currentScri === void 0 ? void 0 : _document$currentScri.src;
|
|
18
|
+
if (!scriptUrl) {
|
|
19
|
+
var _Error$stack, _Error$stack$toString;
|
|
20
|
+
scriptUrl = (_Error$stack = new Error('').stack) === null || _Error$stack === void 0 ? void 0 : (_Error$stack$toString = _Error$stack.toString().match(/(https?:\/\/[^\s]+)/)) === null || _Error$stack$toString === void 0 ? void 0 : _Error$stack$toString[1];
|
|
21
|
+
}
|
|
14
22
|
|
|
15
23
|
// document.currentScript 可能为 null
|
|
16
|
-
var _URL = new URL(
|
|
24
|
+
var _URL = new URL(scriptUrl),
|
|
17
25
|
hostname = _URL.hostname;
|
|
18
26
|
var parts = hostname.split('.');
|
|
19
27
|
var _currentCdnHost = parts.length > 2 ? parts.slice(-2).join('.') : hostname;
|
|
@@ -27,6 +35,9 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
|
|
|
27
35
|
};
|
|
28
36
|
var currentCdnHost = getCurrentCdnHost();
|
|
29
37
|
|
|
38
|
+
// 如果 host 被 o2 插件替换,则可以被用来判断是否需要替换 cdnHost
|
|
39
|
+
var gCdnHost = '//g.alicdn.com/';
|
|
40
|
+
|
|
30
41
|
// 根据不同环境替换 cdn 的域名
|
|
31
42
|
export default function requestInterceptor(_x) {
|
|
32
43
|
return _requestInterceptor.apply(this, arguments);
|
|
@@ -36,7 +47,7 @@ function _requestInterceptor() {
|
|
|
36
47
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
37
48
|
while (1) switch (_context.prev = _context.next) {
|
|
38
49
|
case 0:
|
|
39
|
-
if (currentCdnHost && currentCdnHost !== 'alicdn.com' && whiteList.includes(currentCdnHost)) {
|
|
50
|
+
if (currentCdnHost && currentCdnHost !== 'alicdn.com' && (whiteList.includes(currentCdnHost) || gCdnHost.includes(currentCdnHost))) {
|
|
40
51
|
// if cdn is not alicdn, replace it
|
|
41
52
|
if (config.url) {
|
|
42
53
|
config.url = config.url.replace(new RegExp('.alicdn.com'), ".".concat(currentCdnHost)).replace('cws2.', 'cws.') // 非公有云下无 cws2
|
|
@@ -7,7 +7,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = requestInterceptor;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var
|
|
10
|
+
var _window$ALIYUN_CONSOL;
|
|
11
|
+
// 支持的主权云 CDN Host
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
var whiteList = ['idptcloud01cdn.com', ((_window$ALIYUN_CONSOL = window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.MAIN_RESOURCE_CDN) || 'alicdn.com'];
|
|
11
14
|
var win = window;
|
|
12
15
|
|
|
13
16
|
// 兼容非公有云环境
|
|
@@ -18,9 +21,14 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
|
|
|
18
21
|
if (win.__alfa_cdn_host__) {
|
|
19
22
|
return win.__alfa_cdn_host__;
|
|
20
23
|
}
|
|
24
|
+
var scriptUrl = (_document$currentScri = document.currentScript) === null || _document$currentScri === void 0 ? void 0 : _document$currentScri.src;
|
|
25
|
+
if (!scriptUrl) {
|
|
26
|
+
var _Error$stack, _Error$stack$toString;
|
|
27
|
+
scriptUrl = (_Error$stack = new Error('').stack) === null || _Error$stack === void 0 ? void 0 : (_Error$stack$toString = _Error$stack.toString().match(/(https?:\/\/[^\s]+)/)) === null || _Error$stack$toString === void 0 ? void 0 : _Error$stack$toString[1];
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
// document.currentScript 可能为 null
|
|
23
|
-
var _URL = new URL(
|
|
31
|
+
var _URL = new URL(scriptUrl),
|
|
24
32
|
hostname = _URL.hostname;
|
|
25
33
|
var parts = hostname.split('.');
|
|
26
34
|
var _currentCdnHost = parts.length > 2 ? parts.slice(-2).join('.') : hostname;
|
|
@@ -34,6 +42,9 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
|
|
|
34
42
|
};
|
|
35
43
|
var currentCdnHost = getCurrentCdnHost();
|
|
36
44
|
|
|
45
|
+
// 如果 host 被 o2 插件替换,则可以被用来判断是否需要替换 cdnHost
|
|
46
|
+
var gCdnHost = '//g.alicdn.com/';
|
|
47
|
+
|
|
37
48
|
// 根据不同环境替换 cdn 的域名
|
|
38
49
|
function requestInterceptor(_x) {
|
|
39
50
|
return _requestInterceptor.apply(this, arguments);
|
|
@@ -43,7 +54,7 @@ function _requestInterceptor() {
|
|
|
43
54
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
44
55
|
while (1) switch (_context.prev = _context.next) {
|
|
45
56
|
case 0:
|
|
46
|
-
if (currentCdnHost && currentCdnHost !== 'alicdn.com' && whiteList.includes(currentCdnHost)) {
|
|
57
|
+
if (currentCdnHost && currentCdnHost !== 'alicdn.com' && (whiteList.includes(currentCdnHost) || gCdnHost.includes(currentCdnHost))) {
|
|
47
58
|
// if cdn is not alicdn, replace it
|
|
48
59
|
if (config.url) {
|
|
49
60
|
config.url = config.url.replace(new RegExp('.alicdn.com'), ".".concat(currentCdnHost)).replace('cws2.', 'cws.') // 非公有云下无 cws2
|