mirror of
https://github.com/fluencelabs/dweb-transports
synced 2025-07-02 22:21:45 +00:00
Tweeks to work with ServiceWorker (TransportsProxy in main repo)
This commit is contained in:
@ -4,21 +4,22 @@ const Transports = require('./Transports'); // Manage all Transports that are lo
|
||||
const nodefetch = require('node-fetch'); // Note, were using node-fetch-npm which had a warning in webpack see https://github.com/bitinn/node-fetch/issues/421 and is intended for clients
|
||||
const Url = require('url');
|
||||
|
||||
var fetch,Headers,Request;
|
||||
if (typeof(Window) === "undefined") {
|
||||
//var fetch,Headers,Request;
|
||||
//if (typeof(Window) === "undefined") {
|
||||
if (typeof(fetch) === "undefined") {
|
||||
//var fetch = require('whatwg-fetch').fetch; //Not as good as node-fetch-npm, but might be the polyfill needed for browser.safari
|
||||
//XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; // Note this doesnt work if set to a var or const, needed by whatwg-fetch
|
||||
console.log("Node loaded");
|
||||
fetch = nodefetch;
|
||||
Headers = fetch.Headers; // A class
|
||||
Request = fetch.Request; // A class
|
||||
} else {
|
||||
} /* else {
|
||||
// If on a browser, need to find fetch,Headers,Request in window
|
||||
console.log("Loading browser version of fetch,Headers,Request");
|
||||
fetch = window.fetch;
|
||||
Headers = window.Headers;
|
||||
Request = window.Request;
|
||||
}
|
||||
} */
|
||||
//TODO-HTTP to work on Safari or mobile will require a polyfill, see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch for comment
|
||||
|
||||
defaulthttpoptions = {
|
||||
|
Reference in New Issue
Block a user