main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
890 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | // In case of breaking changes, increase the version
|
---|
| 4 | // number to avoid conflicts.
|
---|
| 5 | const globalOrigin = Symbol.for('undici.globalOrigin.1')
|
---|
| 6 |
|
---|
| 7 | function getGlobalOrigin () {
|
---|
| 8 | return globalThis[globalOrigin]
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | function 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 |
|
---|
| 37 | module.exports = {
|
---|
| 38 | getGlobalOrigin,
|
---|
| 39 | setGlobalOrigin
|
---|
| 40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.