prevent cors and cache options

This commit is contained in:
Sebastian 2023-03-15 09:55:01 -03:00
parent ae4d4647e9
commit f414ca39e4
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069

View File

@ -51,6 +51,8 @@ export async function defaultRequestHandler<T>(
const requestBody = options?.data; const requestBody = options?.data;
const requestTimeout = options?.timeout ?? 5 * 1000; const requestTimeout = options?.timeout ?? 5 * 1000;
const requestParams = options.params ?? {}; const requestParams = options.params ?? {};
const requestPreventCache = options.preventCache ?? false;
const requestPreventCors = options.preventCors ?? false;
const _url = new URL(`${baseUrl}${endpoint}`); const _url = new URL(`${baseUrl}${endpoint}`);
@ -84,7 +86,8 @@ export async function defaultRequestHandler<T>(
headers: requestHeaders, headers: requestHeaders,
method: requestMethod, method: requestMethod,
credentials: "omit", credentials: "omit",
mode: "cors", mode: requestPreventCors ? "no-cors" : "cors",
cache: requestPreventCache ? "no-cache" : "default",
body: payload, body: payload,
signal: controller.signal, signal: controller.signal,
}); });
@ -301,6 +304,8 @@ export interface RequestOptions {
username: string; username: string;
password: string; password: string;
}; };
preventCache?: boolean;
preventCors?: boolean;
data?: any; data?: any;
params?: unknown; params?: unknown;
timeout?: number; timeout?: number;