@@ -16,19 +16,28 @@ import {
1616export class OrkesHttpRequest extends BaseHttpRequest {
1717 private fetchFn : FetchFn ;
1818
19- constructor ( config : OpenAPIConfig ) {
19+ constructor ( config : OpenAPIConfig , customFetch ?: FetchFn ) {
2020 super ( config ) ;
21- const undiciHttp2Agent = new UndiciAgent ( { allowH2 : true } ) ;
22- const undiciHttp2Fetch = async (
23- input : UndiciRequestInfo ,
24- init : UndiciRequestInit = { }
25- ) => {
26- return undiciFetch ( input , {
27- ...init ,
28- dispatcher : undiciHttp2Agent ,
29- } ) ;
30- } ;
31- this . fetchFn = undiciHttp2Fetch as FetchFn ;
21+
22+ if ( customFetch ) {
23+ this . fetchFn = customFetch ;
24+ } else if ( process ?. release ?. name === "node" ) {
25+ // Node.js environment - use undici to make http2 requests
26+ const undiciHttp2Agent = new UndiciAgent ( { allowH2 : true } ) ;
27+ const undiciHttp2Fetch = async (
28+ input : UndiciRequestInfo ,
29+ init ?: UndiciRequestInit
30+ ) => {
31+ return undiciFetch ( input , {
32+ ...init ,
33+ dispatcher : undiciHttp2Agent ,
34+ } ) ;
35+ } ;
36+ this . fetchFn = undiciHttp2Fetch as FetchFn ;
37+ } else {
38+ // Browser environment - use native fetch with http2 support
39+ this . fetchFn = fetch ;
40+ }
3241 }
3342
3443 public request < T > ( options : ApiRequestOptions ) : CancelablePromise < T > {
0 commit comments