From 794000ce79b95528271e7acb1b1894a4d8631af5 Mon Sep 17 00:00:00 2001 From: divine <48183131+divine@users.noreply.github.com> Date: Sun, 7 Feb 2021 00:26:28 +0300 Subject: [PATCH 1/3] Add mode option See https://developer.mozilla.org/en-US/docs/Web/API/Request/mode --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c266c73..0fd4b72 100644 --- a/src/index.js +++ b/src/index.js @@ -30,6 +30,7 @@ * @property {string} [baseURL] a base URL from which to resolve all URLs * @property {typeof window.fetch} [fetch] Custom window.fetch implementation * @property {any} [data] + * @property {'cors'|'same-origin'|'navigate'|'no-cors'|undefined} [mode] The mode of the request (e.g., cors, no-cors, same-origin, or navigate.). Defaults to cors. */ /** @@ -199,7 +200,8 @@ export default (function create(/** @type {Options} */ defaults) { method: _method || options.method, body: data, headers: deepMerge(options.headers, customHeaders, true), - credentials: options.withCredentials ? 'include' : 'same-origin' + credentials: options.withCredentials ? 'include' : 'same-origin', + mode: options.mode ? options.mode : 'cors' }).then((res) => { for (const i in res) { if (typeof res[i] != 'function') response[i] = res[i]; From 13bae92d69dc9d95fe5eea112be349d4a01fcb4b Mon Sep 17 00:00:00 2001 From: divine <48183131+divine@users.noreply.github.com> Date: Sun, 7 Feb 2021 00:37:35 +0300 Subject: [PATCH 2/3] Better typescript typing --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 0fd4b72..8eaf57a 100644 --- a/src/index.js +++ b/src/index.js @@ -30,7 +30,7 @@ * @property {string} [baseURL] a base URL from which to resolve all URLs * @property {typeof window.fetch} [fetch] Custom window.fetch implementation * @property {any} [data] - * @property {'cors'|'same-origin'|'navigate'|'no-cors'|undefined} [mode] The mode of the request (e.g., cors, no-cors, same-origin, or navigate.). Defaults to cors. + * @property {RequestMode} [mode] The mode of the request (e.g., cors, no-cors, same-origin, or navigate.). Defaults to cors. */ /** From c18786656c78127e733a07eae2a2bad852c09020 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 29 Apr 2022 11:40:17 -0400 Subject: [PATCH 3/3] let browser implement the default mode --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 8eaf57a..21661be 100644 --- a/src/index.js +++ b/src/index.js @@ -201,7 +201,7 @@ export default (function create(/** @type {Options} */ defaults) { body: data, headers: deepMerge(options.headers, customHeaders, true), credentials: options.withCredentials ? 'include' : 'same-origin', - mode: options.mode ? options.mode : 'cors' + mode: options.mode }).then((res) => { for (const i in res) { if (typeof res[i] != 'function') response[i] = res[i];