Skip to content

Commit b25abe9

Browse files
committed
API changes added
1 parent 484753e commit b25abe9

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

src/Common/API/CoreAPI.ts

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,8 @@ class CoreAPI {
6161
}
6262
// eslint-disable-next-line dot-notation
6363
options['credentials'] = 'include' as RequestCredentials
64-
let currentUrl: string
65-
if (isProxyHost) {
66-
// Remove leading slash from url if it exists to avoid double slash after /proxy
67-
const proxyUrl = url.startsWith('/') ? url.slice(1) : url
68-
currentUrl = `/proxy/${proxyUrl}`
69-
} else {
70-
currentUrl = `${this.host}/${url}`
71-
}
72-
7364
return fetch(
74-
currentUrl,
65+
`${isProxyHost ? '/proxy' : this.host}/${url}`,
7566
!isMultipartRequest
7667
? options
7768
: ({
@@ -209,8 +200,7 @@ class CoreAPI {
209200
data,
210201
options,
211202
isMultipartRequest,
212-
isProxyHost = false,
213-
}: FetchInTimeParamsType<T> & { isProxyHost?: boolean }): Promise<ResponseType> => {
203+
}: FetchInTimeParamsType<T>): Promise<ResponseType> => {
214204
const controller = options?.abortControllerRef?.current ?? new AbortController()
215205
const timeoutSignal = controller.signal
216206

@@ -280,33 +270,19 @@ class CoreAPI {
280270
data: K,
281271
options?: APIOptions,
282272
isMultipartRequest?: boolean,
283-
isProxyHost?: boolean,
284-
): Promise<ResponseType<T>> =>
285-
this.fetchInTime<K>({ url, type: 'POST', data, options, isMultipartRequest, isProxyHost })
273+
): Promise<ResponseType<T>> => this.fetchInTime<K>({ url, type: 'POST', data, options, isMultipartRequest })
286274

287-
put = <T = any, K = object>(
288-
url: string,
289-
data: K,
290-
options?: APIOptions,
291-
isProxyHost?: boolean,
292-
): Promise<ResponseType<T>> => this.fetchInTime<K>({ url, type: 'PUT', data, options, isProxyHost })
275+
put = <T = any, K = object>(url: string, data: K, options?: APIOptions): Promise<ResponseType<T>> =>
276+
this.fetchInTime<K>({ url, type: 'PUT', data, options })
293277

294-
patch = <T = any, K = object>(
295-
url: string,
296-
data: K,
297-
options?: APIOptions,
298-
isProxyHost?: boolean,
299-
): Promise<ResponseType<T>> => this.fetchInTime<K>({ url, type: 'PATCH', data, options, isProxyHost })
278+
patch = <T = any, K = object>(url: string, data: K, options?: APIOptions): Promise<ResponseType<T>> =>
279+
this.fetchInTime<K>({ url, type: 'PATCH', data, options })
300280

301-
get = <T = any>(url: string, options?: APIOptions, isProxyHost?: boolean): Promise<ResponseType<T>> =>
302-
this.fetchInTime({ url, type: 'GET', data: null, options, isProxyHost })
281+
get = <T = any>(url: string, options?: APIOptions): Promise<ResponseType<T>> =>
282+
this.fetchInTime({ url, type: 'GET', data: null, options })
303283

304-
trash = <T = any, K = object>(
305-
url: string,
306-
data?: K,
307-
options?: APIOptions,
308-
isProxyHost?: boolean,
309-
): Promise<ResponseType<T>> => this.fetchInTime<K>({ url, type: 'DELETE', data, options, isProxyHost })
284+
trash = <T = any, K = object>(url: string, data?: K, options?: APIOptions): Promise<ResponseType<T>> =>
285+
this.fetchInTime<K>({ url, type: 'DELETE', data, options })
310286

311287
setGlobalAPITimeout = (timeout: number) => {
312288
this.timeout = timeout || FALLBACK_REQUEST_TIMEOUT

0 commit comments

Comments
 (0)