1
- import { fetch, FormData, File } from 'node-fetch-native';
1
+ import { fetch, FormData, File } from 'node-fetch-native-with-agent';
2
+ import { createAgent } from 'node-fetch-native-with-agent/agent';
2
3
import { Models } from './models';
3
4
4
5
type Payload = {
@@ -49,7 +50,7 @@ function getUserAgent() {
49
50
// https://common-min-api.proposal.wintercg.org/#requirements-for-navigatoruseragent
50
51
if (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string') {
51
52
ua += ` ${navigator.userAgent}`;
52
-
53
+
53
54
// Older Node.js versions don't have `navigator.userAgent`, so we have to use `process.version`.
54
55
} else if (typeof process !== 'undefined') {
55
56
ua += ` Node.js/${process.version}`;
@@ -61,6 +62,8 @@ function getUserAgent() {
61
62
class Client {
62
63
static CHUNK_SIZE = 1024 * 1024 * 5;
63
64
65
+ fetch = nodeFetch;
66
+
64
67
config = {
65
68
endpoint: '{{ spec .endpoint }}',
66
69
selfSigned: false,
@@ -102,6 +105,10 @@ class Client {
102
105
* @returns {this}
103
106
*/
104
107
setSelfSigned(selfSigned: boolean): this {
108
+ if (typeof globalThis.EdgeRuntime !== 'undefined') {
109
+ console.warn('setSelfSigned is not supported in edge runtimes.');
110
+ }
111
+
105
112
this.config.selfSigned = selfSigned;
106
113
107
114
return this;
@@ -148,7 +155,8 @@ class Client {
148
155
let options: RequestInit = {
149
156
method,
150
157
headers,
151
- credentials: 'include'
158
+ credentials: 'include',
159
+ ...createAgent({ rejectUnauthorized: !this.config.selfSigned }),
152
160
};
153
161
154
162
if (method === 'GET') {
0 commit comments