Skip to content

Commit a644530

Browse files
committed
Update how the node SDK handles self signed requests
The NODE_TLS_REJECT_UNAUTHORIZED env variable will disable SSL checks for all requests. This PR changes the node SDK to only disable SSL checks for Appwrite related requests by passing an option to axios.
1 parent 0ff8df5 commit a644530

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

templates/node/lib/client.js.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const os = require('os');
22
const URL = require('url').URL;
3+
const https = require("https");
34
const axios = require('axios');
45
const FormData = require('form-data');
56
const {{spec.title | caseUcfirst}}Exception = require('./exception.js');
@@ -81,11 +82,6 @@ class Client {
8182
}
8283

8384
async call(method, path = '', headers = {}, params = {}, responseType = 'json') {
84-
if(this.selfSigned) { // Allow self signed requests
85-
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
86-
}
87-
88-
8985
headers = Object.assign({}, this.headers, headers);
9086

9187
let contentType = headers['content-type'].toLowerCase();
@@ -125,6 +121,10 @@ class Client {
125121
json: (contentType.startsWith('application/json')),
126122
responseType: responseType
127123
};
124+
if (this.selfSigned) {
125+
// Allow self signed requests
126+
options.httpsAgent = new https.Agent({ rejectUnauthorized: false });
127+
}
128128
try {
129129
let response = await axios(options);
130130
return response.data;

0 commit comments

Comments
 (0)