@cloud-cli/px 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/proxy-manager.js +25 -15
- package/dist/types.d.ts +1 -0
- package/package.json +4 -2
package/dist/proxy-manager.js
CHANGED
|
@@ -22,11 +22,33 @@ const emptyProxy = {
|
|
|
22
22
|
target: '',
|
|
23
23
|
cors: false,
|
|
24
24
|
redirect: false,
|
|
25
|
+
preserveHost: false,
|
|
25
26
|
redirectUrl: '',
|
|
26
27
|
headers: '',
|
|
27
28
|
authorization: '',
|
|
28
29
|
};
|
|
29
30
|
const readDomain = (options) => (options.domain = options.domain || options.host || options._[0]);
|
|
31
|
+
const numberRe = /^[0-9]+$/;
|
|
32
|
+
const readOption = value => {
|
|
33
|
+
switch (true) {
|
|
34
|
+
case value === 'true':
|
|
35
|
+
return true;
|
|
36
|
+
case value === 'false':
|
|
37
|
+
return false;
|
|
38
|
+
case numberRe.test(value):
|
|
39
|
+
return Number(value);
|
|
40
|
+
default:
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function applyProperties(proxy, options) {
|
|
45
|
+
const properties = ['target', 'cors', 'redirect', 'redirectUrl', 'headers', 'authorization', 'preserveHost'];
|
|
46
|
+
properties.forEach((p) => {
|
|
47
|
+
if (p in options) {
|
|
48
|
+
proxy[p] = readOption(options[p]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
30
52
|
export class ProxyManager {
|
|
31
53
|
constructor() {
|
|
32
54
|
this.server = px;
|
|
@@ -39,15 +61,8 @@ export class ProxyManager {
|
|
|
39
61
|
if (!proxy.target && !proxy.redirectUrl) {
|
|
40
62
|
throw targetNotSpecifiedError;
|
|
41
63
|
}
|
|
42
|
-
const entry = {
|
|
43
|
-
|
|
44
|
-
target: proxy.target,
|
|
45
|
-
cors: !!proxy.cors,
|
|
46
|
-
redirect: !!proxy.redirect,
|
|
47
|
-
redirectUrl: proxy.redirectUrl || '',
|
|
48
|
-
headers: proxy.headers || '',
|
|
49
|
-
authorization: proxy.authorization,
|
|
50
|
-
};
|
|
64
|
+
const entry = { ...emptyProxy };
|
|
65
|
+
applyProperties(entry, proxy);
|
|
51
66
|
set(proxy.domain, entry);
|
|
52
67
|
await this.reload();
|
|
53
68
|
return entry;
|
|
@@ -59,12 +74,7 @@ export class ProxyManager {
|
|
|
59
74
|
if (!proxy) {
|
|
60
75
|
proxy = { ...emptyProxy, domain: host };
|
|
61
76
|
}
|
|
62
|
-
|
|
63
|
-
properties.forEach((p) => {
|
|
64
|
-
if (p in options) {
|
|
65
|
-
proxy[p] = options[p];
|
|
66
|
-
}
|
|
67
|
-
});
|
|
77
|
+
applyProperties(proxy, options);
|
|
68
78
|
set(proxy.domain, proxy);
|
|
69
79
|
await this.reload();
|
|
70
80
|
return proxy;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/px",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "Reverse Proxy",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@cloud-cli/cli": "^1.2.2",
|
|
32
31
|
"@cloud-cli/proxy": "^1.2.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@cloud-cli/cli": "^2.0.0"
|
|
33
35
|
}
|
|
34
36
|
}
|