-
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathENVIRONMENT.mjs
111 lines (68 loc) · 1.81 KB
/
ENVIRONMENT.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { URL } from '../source/parser/URL.mjs';
const flags = ((global) => {
let flags = {
cause: null,
code: null,
debug: false,
url: URL.parse()
};
let tmp1 = (global.location || {}).search || '';
let tmp2 = (global.parent.location || {}).search || '';
if (tmp1.includes('debug') === true) {
flags.debug = true;
} else if (tmp2.includes('debug') === true) {
flags.debug = true;
}
if (tmp1.startsWith('?') === true) {
tmp1.substr(1).split('&').forEach((flag) => {
let tmp = flag.split('=');
if (tmp.length >= 2) {
let key = tmp[0];
let val = tmp.slice(1).join('=');
if (key === 'url') {
flags[key] = URL.parse(decodeURIComponent(val));
} else {
let num = parseInt(val, 10);
if (Number.isNaN(num) === false && (num).toString() === val) {
val = num;
}
if (val === 'true') val = true;
if (val === 'false') val = false;
if (val === 'null') val = null;
flags[key] = val;
}
}
});
}
return flags;
})(typeof window !== 'undefined' ? window : this);
const hostname = ((global) => {
let host = 'localhost';
let tmp1 = (global.location || {}).host || '';
if (tmp1.includes(':') === true) {
let tmp2 = tmp1.split(':').slice(0, -1).join(':');
if (tmp2 !== 'localhost') {
host = tmp2;
}
} else if (tmp1 !== '') {
host = tmp1;
}
return host;
})(typeof window !== 'undefined' ? window : this);
const secure = ((global) => {
let secure = true;
let tmp1 = (global.location || {}).protocol || '';
if (tmp1.includes(':') === true) {
let tmp2 = tmp1.split(':').shift();
if (tmp2 !== 'https') {
secure = false;
}
}
return secure;
})(typeof window !== 'undefined' ? window : this);
const ENVIRONMENT = {
flags: flags,
hostname: hostname,
secure: secure
};
export { ENVIRONMENT };