etherreq 1.2.4 → 1.2.5
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.
- package/dist/request.js +12 -2
- package/package.json +1 -1
package/dist/request.js
CHANGED
|
@@ -81,8 +81,18 @@ function getCacheTTL(config) {
|
|
|
81
81
|
* @param options - 请求配置
|
|
82
82
|
*/
|
|
83
83
|
export const request = (url, options = {}) => {
|
|
84
|
-
|
|
85
|
-
const
|
|
84
|
+
// 如果 options.baseURL 存在则使用它,否则使用全局 _baseURL,如果都不存在则使用当前页面的 origin
|
|
85
|
+
const baseURL = options.baseURL || _baseURL || (typeof window !== 'undefined' ? window.location.origin : '');
|
|
86
|
+
// 构造最终的 URL,如果 baseURL 为空则直接使用传入的 url
|
|
87
|
+
let finalURL;
|
|
88
|
+
if (baseURL && !url.startsWith('http')) {
|
|
89
|
+
// 只有当 url 不是绝对 URL 时才拼接 baseURL
|
|
90
|
+
finalURL = new URL(url, baseURL).toString();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// 如果 url 是绝对 URL 或者 baseURL 为空,则直接使用 url
|
|
94
|
+
finalURL = url;
|
|
95
|
+
}
|
|
86
96
|
return instance({
|
|
87
97
|
...options,
|
|
88
98
|
url: finalURL,
|