1'use strict' 2 3// In case of breaking changes, increase the version 4// number to avoid conflicts. 5const globalOrigin = Symbol.for('undici.globalOrigin.1') 6 7function getGlobalOrigin () { 8 return globalThis[globalOrigin] 9} 10 11function setGlobalOrigin (newOrigin) { 12 if (newOrigin === undefined) { 13 Object.defineProperty(globalThis, globalOrigin, { 14 value: undefined, 15 writable: true, 16 enumerable: false, 17 configurable: false 18 }) 19 20 return 21 } 22 23 const parsedURL = new URL(newOrigin) 24 25 if (parsedURL.protocol !== 'http:' && parsedURL.protocol !== 'https:') { 26 throw new TypeError(`Only http & https urls are allowed, received ${parsedURL.protocol}`) 27 } 28 29 Object.defineProperty(globalThis, globalOrigin, { 30 value: parsedURL, 31 writable: true, 32 enumerable: false, 33 configurable: false 34 }) 35} 36 37module.exports = { 38 getGlobalOrigin, 39 setGlobalOrigin 40} 41