Skip to content

Commit e70a76e

Browse files
committed
fix(ReqFetch): 浏览器环境下设置默认 prefixUrl 值,修复 pathname 格式的 api 请求异常的问题
1 parent 0180976 commit e70a76e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/common/async.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: lzw
33
* @Date: 2022-01-12 15:10:41
44
* @LastEditors: renxia
5-
* @LastEditTime: 2024-02-27 13:17:29
5+
* @LastEditTime: 2024-03-12 15:36:09
66
* @Description:
77
* @see src\vs\base\common\async.ts
88
*/
@@ -431,7 +431,7 @@ export async function retry<T>(
431431
* await concurrencyTest(100);
432432
* ```
433433
*/
434-
export function concurrency<T, E = T | undefined>(taskList: ITask<Promise<T>>[], maxDegreeOfParalellism = 5) {
434+
export function concurrency<T, E = T | Error>(taskList: ITask<Promise<T>>[], maxDegreeOfParalellism = 5) {
435435
const total = taskList.length;
436436
let idx = 0;
437437
const resut: { index: number; result: T; error: E }[] = [];

src/common/lib/LRUCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @see https://www.npmjs.com/package/lru-cache
22

33
export interface LRUCacheOptions<K = string, V = unknown> {
4-
/** The maximum number of items that remain in the cache */
4+
/** The maximum number of items that remain in the cache. default 500 */
55
max?: number;
6-
/** how long to live in ms */
6+
/** how long to live in ms. default 0 */
77
ttl?: number;
88
updateAgeOnGet?: boolean;
99
/** Function that is called on items when they are dropped from the cache */

src/common/lib/ReqFetch.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: renxia
33
* @Date: 2024-01-15 11:26:52
44
* @LastEditors: renxia
5-
* @LastEditTime: 2024-02-02 11:08:37
5+
* @LastEditTime: 2024-03-14 09:46:01
66
* @Description:
77
*/
88
import type { OutgoingHttpHeaders } from 'node:http';
@@ -32,13 +32,15 @@ export class ReqBase {
3232
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
3333
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
3434
};
35+
protected isBrowser = typeof document !== 'undefined' && typeof window !== 'undefined';
3536
protected config: ReqConfig = {};
3637
constructor(config?: string | ReqConfig, headers?: OutgoingHttpHeaders) {
3738
if (config) {
3839
if (typeof config === 'string') config = { cookie: config };
3940
config = assign(this.config, config);
4041
}
4142

43+
if (this.isBrowser && !this.config.prefixUrl) this.config.prefixUrl = location.origin;
4244
if (this.config.cookie) this.setCookie(this.config.cookie);
4345
if (this.config.headers) this.setHeaders(this.config.headers);
4446
if (headers) this.setHeaders(headers);
@@ -49,7 +51,7 @@ export class ReqBase {
4951
...toLowcaseKeyObject(headers),
5052
};
5153

52-
if (urlObject) {
54+
if (!this.isBrowser && urlObject) {
5355
if (!headers.host) headers.host = urlObject.host;
5456
if (!headers.origin) headers.origin = urlObject.origin || `${urlObject.protocol}://${urlObject.hostname}`;
5557
}

0 commit comments

Comments
 (0)