@cloud-cli/px 3.5.4 → 3.5.6
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.d.ts +1 -0
- package/dist/proxy-manager.js +22 -16
- package/package.json +1 -1
package/dist/proxy-manager.d.ts
CHANGED
package/dist/proxy-manager.js
CHANGED
|
@@ -11,8 +11,10 @@ export class ProxyManager {
|
|
|
11
11
|
if (!proxy.target && !proxy.redirectUrl) {
|
|
12
12
|
return reject(targetNotSpecifiedError);
|
|
13
13
|
}
|
|
14
|
+
const [domain, path = ''] = (proxy.domain || proxy.host).split('/');
|
|
14
15
|
const entry = new Proxy({
|
|
15
|
-
domain:
|
|
16
|
+
domain: domain,
|
|
17
|
+
path: path,
|
|
16
18
|
target: proxy.target,
|
|
17
19
|
cors: !!proxy.cors,
|
|
18
20
|
redirect: !!proxy.redirect,
|
|
@@ -29,33 +31,30 @@ export class ProxyManager {
|
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
async updateProxy(options) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const proxies = await Resource.find(Proxy, query);
|
|
34
|
+
const host = options.domain || options.host;
|
|
35
|
+
const proxies = await this.findByDomainAndPath(host);
|
|
35
36
|
if (!proxies.length) {
|
|
36
|
-
|
|
37
|
+
const [domain, path = ''] = host.split('/');
|
|
38
|
+
proxies.push(new Proxy({ domain, path }));
|
|
37
39
|
}
|
|
38
40
|
for (const proxy of proxies) {
|
|
39
|
-
['target', 'cors', 'redirect', 'redirectUrl'].forEach(p => p in options && (proxy[p] = options[p]));
|
|
41
|
+
['target', 'cors', 'redirect', 'redirectUrl'].forEach((p) => p in options && (proxy[p] = options[p]));
|
|
40
42
|
await proxy.save();
|
|
41
43
|
}
|
|
42
44
|
return true;
|
|
43
45
|
}
|
|
44
46
|
removeProxy(options) {
|
|
45
47
|
return new Promise(async (resolve, reject) => {
|
|
46
|
-
|
|
48
|
+
const host = options.domain || options.host;
|
|
49
|
+
if (!host) {
|
|
47
50
|
return reject(domainNotSpecifiedError);
|
|
48
51
|
}
|
|
49
|
-
const
|
|
50
|
-
if (options.target) {
|
|
51
|
-
query.where('target').is(options.target);
|
|
52
|
-
}
|
|
53
|
-
const proxy = await Resource.find(Proxy, query);
|
|
52
|
+
const proxies = await this.findByDomainAndPath(host);
|
|
54
53
|
try {
|
|
55
|
-
for (const p of
|
|
54
|
+
for (const p of proxies) {
|
|
56
55
|
await p.remove();
|
|
57
56
|
}
|
|
58
|
-
resolve(
|
|
57
|
+
resolve({ found: proxies.length });
|
|
59
58
|
}
|
|
60
59
|
catch (error) {
|
|
61
60
|
reject(error);
|
|
@@ -64,12 +63,19 @@ export class ProxyManager {
|
|
|
64
63
|
}
|
|
65
64
|
async getDomainList() {
|
|
66
65
|
const proxies = await Resource.find(Proxy, new Query());
|
|
67
|
-
|
|
66
|
+
const list = proxies.map((proxy) => proxy.domain);
|
|
67
|
+
return [...new Set(list)];
|
|
68
68
|
}
|
|
69
69
|
async getProxyList() {
|
|
70
70
|
return Resource.find(Proxy, new Query());
|
|
71
71
|
}
|
|
72
72
|
getProxyListForDomain(options) {
|
|
73
|
-
return
|
|
73
|
+
return this.findByDomainAndPath(options.domain || options.host);
|
|
74
|
+
}
|
|
75
|
+
async findByDomainAndPath(string) {
|
|
76
|
+
const [domain, path = ''] = string.split('/');
|
|
77
|
+
const query = new Query().where('domain').is(domain).where('path').is(path);
|
|
78
|
+
const proxies = await Resource.find(Proxy, query);
|
|
79
|
+
return proxies;
|
|
74
80
|
}
|
|
75
81
|
}
|