source: node_modules/undici/lib/fetch/global.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 890 bytes
Line 
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}
Note: See TracBrowser for help on using the repository browser.