Skip to content

Commit

Permalink
Merge pull request #5 from Chia-Network/fix-ssl-sert
Browse files Browse the repository at this point in the history
Fix ssl sert
  • Loading branch information
Rigidity authored Apr 6, 2023
2 parents f3a30c3 + 0529b35 commit d0352d9
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/clients/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import { Response } from './Response';

export interface ClientOptions {
host: string;
port: number;
protocol: 'http' | 'https';
keyPath: string;
certPath: string;
caCertPath: string;
}

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;
Expand All @@ -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(
Expand Down Expand Up @@ -60,25 +59,21 @@ 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;
this.keyPath = options.keyPath;
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,
});
}

Expand Down

0 comments on commit d0352d9

Please sign in to comment.