Tweeks to work with ServiceWorker (TransportsProxy in main repo)

This commit is contained in:
Mitra Ardron
2018-04-13 17:26:44 +10:00
parent eda896fe67
commit 93228d71fd
5 changed files with 31 additions and 18 deletions

View File

@ -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 = {