From 97154f59fb85f04ae0d3b421fb250a9cb9a3b61d Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Tue, 24 Oct 2023 14:10:33 -0600 Subject: [PATCH] Fix CORS stuff when requesting other origins (ie, the AI servers) --- src/lib/requests.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/requests.ts b/src/lib/requests.ts index 492bea5f99..23f4ec09dc 100644 --- a/src/lib/requests.ts +++ b/src/lib/requests.ts @@ -123,12 +123,14 @@ function request(method: Method): RequestFunction { } } + const same_origin = url.indexOf("://") < 0 || url.indexOf(window.location.origin) === 0; + fetch(url, { signal, method, - credentials: "include", + credentials: same_origin ? "include" : undefined, keepalive: true, - mode: csrf_safe ? "no-cors" : "cors", + mode: same_origin ? (csrf_safe ? "no-cors" : "cors") : undefined, cache: cacheable ? "default" : "no-cache", body: prepared_data as any, headers,