diff --git a/packages/server/src/definitions/datasource.ts b/packages/server/src/definitions/datasource.ts index 6e19d9d342..1ef5206fff 100644 --- a/packages/server/src/definitions/datasource.ts +++ b/packages/server/src/definitions/datasource.ts @@ -31,6 +31,7 @@ export interface BearerAuthConfig { export interface RestConfig { url: string + rejectUnauthorized: boolean defaultHeaders: { [key: string]: any } diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index d50837b273..fac8403c49 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -8,6 +8,7 @@ function runServer() { checkDevelopmentEnvironment() fixPath() // this will setup http and https proxies form env variables + process.env.GLOBAL_AGENT_FORCE_GLOBAL_AGENT = "false" bootstrap() require("./app") } diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index f0f254c0ea..cab8263720 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -14,6 +14,7 @@ import { BearerAuthConfig, } from "../definitions/datasource" import { get } from "lodash" +import * as https from "https" import qs from "querystring" const fetch = require("node-fetch") const { formatBytes } = require("../utilities") @@ -76,6 +77,11 @@ const SCHEMA: Integration = { required: false, default: {}, }, + rejectUnauthorized: { + type: DatasourceFieldType.BOOLEAN, + default: true, + required: false, + }, legacyHttpParser: { display: "Legacy HTTP Support", type: DatasourceFieldType.BOOLEAN, @@ -218,8 +224,12 @@ class RestIntegration implements IntegrationBase { } } - // make sure the query string is fully encoded - const main = `${path}?${qs.encode(qs.decode(queryString))}` + if (queryString) { + // make sure the query string is fully encoded + queryString = "?" + qs.encode(qs.decode(queryString)) + } + const main = `${path}${queryString}` + let complete = main if (this.config.url && !main.startsWith("http")) { complete = !this.config.url ? main : `${this.config.url}/${main}` @@ -381,6 +391,12 @@ class RestIntegration implements IntegrationBase { paginationValues ) + if (this.config.rejectUnauthorized == false) { + input.agent = new https.Agent({ + rejectUnauthorized: false, + }) + } + if (this.config.legacyHttpParser) { // https://github.com/nodejs/node/issues/43798 input.extraHttpOptions = { insecureHTTPParser: true }