From 0529b356ca7cad18373430bf5b69bf0c83fd9153 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Thu, 6 Apr 2023 14:15:49 -0400 Subject: [PATCH] Fix ssl sert --- src/clients/Client.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/clients/Client.ts b/src/clients/Client.ts index 42849a0..51ac055 100644 --- a/src/clients/Client.ts +++ b/src/clients/Client.ts @@ -9,8 +9,6 @@ import { Response } from './Response'; export interface ClientOptions { host: string; - port: number; - protocol: 'http' | 'https'; keyPath: string; certPath: string; caCertPath: string; @@ -18,8 +16,7 @@ export interface ClientOptions { export abstract class Client { public host: string; - public port: number | null; - public protocol: 'http' | 'https'; + public port: number | null = null; public keyPath: string; public certPath: string; public caCertPath: string | boolean; @@ -28,7 +25,9 @@ export abstract class Client { public options: ClientOptions | null; public get baseUrl(): string { - return `${this.protocol}://${this.host}:${this.port}`; + if (!this.port) throw new Error('Port is not set.'); + + return `https://${this.host}:${this.port}`; } constructor( @@ -60,8 +59,6 @@ export abstract class Client { this.config.private_ssl_ca.crt ); this.host = this.config.self_hostname; - this.port = null; - this.protocol = 'https'; } else { this.config = null; this.options = options; @@ -69,16 +66,14 @@ export abstract class Client { this.certPath = options.certPath; this.caCertPath = options.caCertPath; this.host = options.host; - this.port = options.port; - this.protocol = options.protocol; } this.agent = new Agent({ - ...(typeof this.caCertPath !== 'boolean' + ...(this.caCertPath ? { ca: fs.readFileSync(this.caCertPath) } : {}), cert: fs.readFileSync(this.certPath), key: fs.readFileSync(this.keyPath), - rejectUnauthorized: this.host !== 'localhost', + rejectUnauthorized: false, }); }