Add flag for TLS use
This commit is contained in:
parent
8be899e012
commit
fd5fc40f69
3
dist/src/transport/http.d.ts
vendored
3
dist/src/transport/http.d.ts
vendored
@ -5,11 +5,12 @@ import { NotificationMethod, NotificationParams, RequestMethod, RPCRequestAndRes
|
||||
import { Transport } from ".";
|
||||
export declare class HttpTransport {
|
||||
Notifications: EventEmitter<NotificationMethod, NotificationParams>;
|
||||
static createTransport(server: string): Promise<Transport>;
|
||||
static createTransport(server: string, tls?: boolean): Promise<Transport>;
|
||||
sendRequest<K extends RequestMethod>(req: RPCRequestAndResponses[K][0]): Promise<unknown>;
|
||||
Close(): Promise<void>;
|
||||
private ws;
|
||||
private server;
|
||||
private tls;
|
||||
private constructor();
|
||||
}
|
||||
export declare function unsecureHttpsAgent(): https.Agent;
|
||||
|
||||
10
dist/src/transport/http.js
vendored
10
dist/src/transport/http.js
vendored
@ -11,9 +11,9 @@ const eventemitter3_1 = require("eventemitter3");
|
||||
const serde_1 = require("../serde");
|
||||
class HttpTransport {
|
||||
Notifications;
|
||||
static async createTransport(server) {
|
||||
static async createTransport(server, tls = true) {
|
||||
// eslint-disable-next-line new-cap
|
||||
const ws = new websocket_1.w3cwebsocket(`wss://${server}/subscribe`);
|
||||
const ws = new websocket_1.w3cwebsocket(`${tls ? 'wss' : 'ws'}://${server}/subscribe`);
|
||||
// throw any websocket errors so we don't fail silently
|
||||
ws.onerror = (e) => {
|
||||
console.error("Error with websocket connection to server: " + e);
|
||||
@ -25,7 +25,7 @@ class HttpTransport {
|
||||
return transport;
|
||||
}
|
||||
async sendRequest(req) {
|
||||
const url = new URL(`https://${this.server}`).toString();
|
||||
const url = new URL(`${this.tls ? 'https' : 'http'}://${this.server}`).toString();
|
||||
const result = await axios_1.default.post(url.toString(), JSON.stringify(req));
|
||||
return result.data;
|
||||
}
|
||||
@ -34,9 +34,11 @@ class HttpTransport {
|
||||
}
|
||||
ws;
|
||||
server;
|
||||
constructor(ws, server) {
|
||||
tls;
|
||||
constructor(ws, server, tls = true) {
|
||||
this.ws = ws;
|
||||
this.server = server;
|
||||
this.tls = tls;
|
||||
this.Notifications = new eventemitter3_1.EventEmitter();
|
||||
this.ws.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data.toString());
|
||||
|
||||
2
dist/tsconfig.tsbuildinfo
vendored
2
dist/tsconfig.tsbuildinfo
vendored
File diff suppressed because one or more lines are too long
@ -17,9 +17,9 @@ import { Transport } from ".";
|
||||
export class HttpTransport {
|
||||
Notifications: EventEmitter<NotificationMethod, NotificationParams>;
|
||||
|
||||
public static async createTransport(server: string): Promise<Transport> {
|
||||
public static async createTransport(server: string, tls: boolean = true): Promise<Transport> {
|
||||
// eslint-disable-next-line new-cap
|
||||
const ws = new w3cwebsocket(`wss://${server}/subscribe`);
|
||||
const ws = new w3cwebsocket(`${tls ? 'wss' : 'ws'}://${server}/subscribe`);
|
||||
|
||||
// throw any websocket errors so we don't fail silently
|
||||
ws.onerror = (e) => {
|
||||
@ -37,7 +37,7 @@ export class HttpTransport {
|
||||
public async sendRequest<K extends RequestMethod>(
|
||||
req: RPCRequestAndResponses[K][0]
|
||||
): Promise<unknown> {
|
||||
const url = new URL(`https://${this.server}`).toString();
|
||||
const url = new URL(`${this.tls ? 'https' : 'http'}://${this.server}`).toString();
|
||||
|
||||
const result = await axios.post(url.toString(), JSON.stringify(req));
|
||||
|
||||
@ -51,10 +51,12 @@ export class HttpTransport {
|
||||
private ws: w3cwebsocket;
|
||||
|
||||
private server: string;
|
||||
private tls: boolean;
|
||||
|
||||
private constructor(ws: w3cwebsocket, server: string) {
|
||||
private constructor(ws: w3cwebsocket, server: string, tls: boolean = true) {
|
||||
this.ws = ws;
|
||||
this.server = server;
|
||||
this.tls = tls
|
||||
|
||||
this.Notifications = new EventEmitter();
|
||||
this.ws.onmessage = (event) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user