From 00356d669c765b9f9b47d7a619d73d734fffd594 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Mon, 8 Aug 2022 19:12:29 +0200 Subject: properly initialize fetch in ApiClient --- web/pw-server/src/lib/api_client.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'web/pw-server') diff --git a/web/pw-server/src/lib/api_client.ts b/web/pw-server/src/lib/api_client.ts index 2eaa762..706d958 100644 --- a/web/pw-server/src/lib/api_client.ts +++ b/web/pw-server/src/lib/api_client.ts @@ -1,3 +1,4 @@ +import { browser } from "$app/env"; import { get_session_token } from "./auth"; export type FetchFn = (input: RequestInfo, init?: RequestInit) => Promise; @@ -15,8 +16,8 @@ export class ApiClient { constructor(fetch_fn?: FetchFn) { if (fetch_fn) { this.fetch_fn = fetch_fn; - } else { - this.fetch_fn = fetch; + } else if (browser) { + this.fetch_fn = fetch.bind(window); } // TODO: maybe it is cleaner to pass this as a parameter -- cgit v1.2.3