Skip to content

Commit 79cdd26

Browse files
committed
feat: support self signed
1 parent 107507c commit 79cdd26

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

templates/node/package.json.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
"typescript": "5.4.2"
4545
},
4646
"dependencies": {
47-
"node-fetch-native": "1.6.2"
47+
"node-fetch-native-with-agent": "1.7.0"
4848
}
4949
}

templates/node/src/client.ts.twig

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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';
23
import { Models } from './models';
34

45
type Payload = {
@@ -49,7 +50,7 @@ function getUserAgent() {
4950
// https://common-min-api.proposal.wintercg.org/#requirements-for-navigatoruseragent
5051
if (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string') {
5152
ua += ` ${navigator.userAgent}`;
52-
53+
5354
// Older Node.js versions don't have `navigator.userAgent`, so we have to use `process.version`.
5455
} else if (typeof process !== 'undefined') {
5556
ua += ` Node.js/${process.version}`;
@@ -61,6 +62,8 @@ function getUserAgent() {
6162
class Client {
6263
static CHUNK_SIZE = 1024 * 1024 * 5;
6364

65+
fetch = nodeFetch;
66+
6467
config = {
6568
endpoint: '{{ spec.endpoint }}',
6669
selfSigned: false,
@@ -102,6 +105,10 @@ class Client {
102105
* @returns {this}
103106
*/
104107
setSelfSigned(selfSigned: boolean): this {
108+
if (typeof globalThis.EdgeRuntime !== 'undefined') {
109+
console.warn('setSelfSigned is not supported in edge runtimes.');
110+
}
111+
105112
this.config.selfSigned = selfSigned;
106113

107114
return this;
@@ -148,7 +155,8 @@ class Client {
148155
let options: RequestInit = {
149156
method,
150157
headers,
151-
credentials: 'include'
158+
credentials: 'include',
159+
...createAgent({ rejectUnauthorized: !this.config.selfSigned }),
152160
};
153161

154162
if (method === 'GET') {

0 commit comments

Comments
 (0)