UNPKG

@bsv/sdk

Version:

BSV Blockchain Software Development Kit

38 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultHttpClient = void 0; const NodejsHttpClient_js_1 = require("./NodejsHttpClient.js"); const FetchHttpClient_js_1 = require("./FetchHttpClient.js"); /** * Returns a default HttpClient implementation based on the environment that it is run on. * This method will attempt to use `window.fetch` if available (in browser environments). * If running in a Node environment, it falls back to using the Node `https` module */ function defaultHttpClient() { const noHttpClient = { async request(..._) { throw new Error('No method available to perform HTTP request'); } }; if (typeof window !== 'undefined' && typeof window.fetch === 'function') { // Use fetch in a browser environment return new FetchHttpClient_js_1.FetchHttpClient(window.fetch.bind(window)); } else if (typeof require !== 'undefined') { // Use Node https module // eslint-disable-next-line try { // eslint-disable-next-line @typescript-eslint/no-var-requires const https = require('https'); return new NodejsHttpClient_js_1.NodejsHttpClient(https); } catch (e) { return noHttpClient; } } else { return noHttpClient; } } exports.defaultHttpClient = defaultHttpClient; //# sourceMappingURL=DefaultHttpClient.js.map