Skip to content

Commit

Permalink
add --insecure/-k flag to allow insecure requests
Browse files Browse the repository at this point in the history
The flags are based on the same ones in cURL. With the flag added, it will create an https agent
that does not reject bad certificates.

fix hasura#143
  • Loading branch information
stormsweeper committed Mar 19, 2024
1 parent 7492019 commit e899afa
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 47 deletions.
84 changes: 42 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const makeClient = options => {
websocket,
headers,
hook,
allowInsecure,
} = options;

const clientContext = {
httpsAgent: null,
endpoint,
headers: cloneObject(headers || {}),
websocket: {
Expand All @@ -30,6 +32,15 @@ const makeClient = options => {
},
};

if (allowInsecure) {
try {
const nodeHttps = require('node:https');
clientContext.httpsAgent = new nodeHttps.Agent({rejectUnauthorized: false});
} catch (e) {
console.error(e);
}
}

const executeQuery = async (queryOptions, successCallback, errorCallback) => {
const {
query,
Expand All @@ -53,6 +64,7 @@ const makeClient = options => {
method: 'POST',
headers,
body: JSON.stringify({query, variables: (variables || {})}),
agent: clientContext.httpsAgent,
},
);
const responseObj = await response.json();
Expand Down
Loading

0 comments on commit e899afa

Please sign in to comment.