properly initialize fetch in ApiClient
This commit is contained in:
parent
cf52ab6f7f
commit
00356d669c
1 changed files with 3 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { browser } from "$app/env";
|
||||||
import { get_session_token } from "./auth";
|
import { get_session_token } from "./auth";
|
||||||
|
|
||||||
export type FetchFn = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
export type FetchFn = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
||||||
|
@ -15,8 +16,8 @@ export class ApiClient {
|
||||||
constructor(fetch_fn?: FetchFn) {
|
constructor(fetch_fn?: FetchFn) {
|
||||||
if (fetch_fn) {
|
if (fetch_fn) {
|
||||||
this.fetch_fn = fetch_fn;
|
this.fetch_fn = fetch_fn;
|
||||||
} else {
|
} else if (browser) {
|
||||||
this.fetch_fn = fetch;
|
this.fetch_fn = fetch.bind(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: maybe it is cleaner to pass this as a parameter
|
// TODO: maybe it is cleaner to pass this as a parameter
|
||||||
|
|
Loading…
Reference in a new issue