Commit ba598fec authored by Lê Bảo Hồng Đức's avatar Lê Bảo Hồng Đức

[tag]0.1-vcci

parents a8c42c76 9679ec88
Pipeline #52409 passed with stages
in 2 minutes and 16 seconds
...@@ -168,7 +168,16 @@ const withNoopCancel = <T>(promise: Promise<T>): CustomClientPromise<T> => { ...@@ -168,7 +168,16 @@ const withNoopCancel = <T>(promise: Promise<T>): CustomClientPromise<T> => {
return nextPromise; return nextPromise;
}; };
const useCustomClient = <T>(url: string, options?: RequestInit): Promise<T> => { const API_PREFIX = "/api/v1.0";
const normalizeApiUrl = (url: string): string => {
if (/^https?:\/\//i.test(url)) return url;
if (url.startsWith(`${API_PREFIX}/`) || url.startsWith(`${API_PREFIX}?`)) return url;
return `${API_PREFIX}${url.startsWith("/") ? "" : "/"}${url}`;
};
const useCustomClient = <T>(rawUrl: string, options?: RequestInit): Promise<T> => {
const url = normalizeApiUrl(rawUrl);
const method = getRequestMethod(options); const method = getRequestMethod(options);
const shouldCacheGet = shouldUseGetCache(url, options); const shouldCacheGet = shouldUseGetCache(url, options);
const cacheKey = shouldCacheGet ? makeGetCacheKey(url, options) : ""; const cacheKey = shouldCacheGet ? makeGetCacheKey(url, options) : "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment