File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,18 @@ import { requestHeadersWithDefaults } from "../utils/rpc.js";
3
3
import type { IHttpTransportConfig } from "./types/IHttpTransportConfig.js" ;
4
4
import type { ITransport } from "./types/ITransport.js" ;
5
5
6
+ const getIsomorphicFetch = ( ) => {
7
+ if ( typeof window !== "undefined" ) {
8
+ return window . fetch . bind ( window ) ;
9
+ }
10
+
11
+ if ( typeof globalThis !== "undefined" ) {
12
+ return globalThis . fetch ;
13
+ }
14
+
15
+ throw new Error ( "No fetch implementation found" ) ;
16
+ } ;
17
+
6
18
/**
7
19
* HttpTransport represents the HTTP transport for connecting to the network.
8
20
*
@@ -35,7 +47,7 @@ class HttpTransport implements ITransport {
35
47
this . endpoint = endpoint ;
36
48
this . timeout = timeout ;
37
49
this . headers = requestHeadersWithDefaults ( headers ) ;
38
- this . fetcher = fetcher || globalThis . fetch ;
50
+ this . fetcher = fetcher || getIsomorphicFetch ( ) ;
39
51
}
40
52
41
53
/**
You can’t perform that action at this time.
0 commit comments