@cloud-cli/px 4.2.6 → 4.2.8
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 -19
- package/package.json +1 -1
package/dist/proxy-manager.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare class ProxyManager {
|
|
|
6
6
|
updateProxy(options: WithOptionalProps<Proxy>): Promise<Proxy>;
|
|
7
7
|
removeProxy(options: WithOptionalProps<DomainAndTarget>): Promise<boolean>;
|
|
8
8
|
getDomainList(): Promise<string[]>;
|
|
9
|
+
getProxyListWithContainers(): Promise<Proxy[]>;
|
|
9
10
|
getProxyList(filters?: Partial<Proxy>): Promise<Proxy[]>;
|
|
10
11
|
getProxyListForDomain(options: WithOptionalProps<DomainName>): Promise<Proxy[]>;
|
|
11
12
|
reload(): Promise<void>;
|
package/dist/proxy-manager.js
CHANGED
|
@@ -22,13 +22,15 @@ const emptyProxy = {
|
|
|
22
22
|
domain: '',
|
|
23
23
|
target: '',
|
|
24
24
|
cors: false,
|
|
25
|
-
preserveHost:
|
|
25
|
+
preserveHost: true,
|
|
26
26
|
redirect: false,
|
|
27
27
|
redirectUrl: '',
|
|
28
28
|
headers: '',
|
|
29
29
|
authorization: '',
|
|
30
30
|
};
|
|
31
|
-
const readDomain = (options) =>
|
|
31
|
+
const readDomain = (options) => {
|
|
32
|
+
options.domain = options.domain || options.host || options._[0];
|
|
33
|
+
};
|
|
32
34
|
const numberRe = /^[0-9]+$/;
|
|
33
35
|
const readOption = value => {
|
|
34
36
|
switch (true) {
|
|
@@ -100,10 +102,18 @@ export class ProxyManager {
|
|
|
100
102
|
const proxies = await this.getProxyList();
|
|
101
103
|
return proxies.map((proxy) => proxy.domain);
|
|
102
104
|
}
|
|
103
|
-
async
|
|
105
|
+
async getProxyListWithContainers() {
|
|
104
106
|
const staticRoutes = getAll();
|
|
105
|
-
const containers = await this.getRunningContainers();
|
|
106
|
-
const
|
|
107
|
+
const containers = (await this.getRunningContainers()).map(readProxyFromContainer);
|
|
108
|
+
const containerDomains = containers.map(c => c.domain.split('/')[0]);
|
|
109
|
+
const list = [
|
|
110
|
+
...staticRoutes.filter(t => !containerDomains.includes(t.domain)),
|
|
111
|
+
...containers,
|
|
112
|
+
];
|
|
113
|
+
return list;
|
|
114
|
+
}
|
|
115
|
+
async getProxyList(filters = {}) {
|
|
116
|
+
const list = await this.getProxyListWithContainers();
|
|
107
117
|
const keys = Object.keys(filters);
|
|
108
118
|
if (!keys.length) {
|
|
109
119
|
return list;
|
|
@@ -115,19 +125,17 @@ export class ProxyManager {
|
|
|
115
125
|
}
|
|
116
126
|
async getProxyListForDomain(options) {
|
|
117
127
|
readDomain(options);
|
|
118
|
-
const all = await this.
|
|
119
|
-
return all.filter((p) => p.domain
|
|
128
|
+
const all = await this.getProxyListWithContainers();
|
|
129
|
+
return all.filter((p) => p.domain.includes(options.domain));
|
|
120
130
|
}
|
|
121
131
|
async reload() {
|
|
122
|
-
const
|
|
123
|
-
const containers = await this.getRunningContainers();
|
|
124
|
-
const all = [...targets, ...containers.map(readProxyFromContainer)];
|
|
132
|
+
const all = await this.getProxyListWithContainers();
|
|
125
133
|
px.reset();
|
|
126
134
|
for (const t of all) {
|
|
127
135
|
const [domain, path = ""] = t.domain.split("/");
|
|
128
136
|
px.add(new ProxyEntry({
|
|
129
|
-
domain
|
|
130
|
-
path
|
|
137
|
+
domain,
|
|
138
|
+
path,
|
|
131
139
|
target: t.target,
|
|
132
140
|
redirectToHttps: t.redirect,
|
|
133
141
|
redirectToUrl: t.redirectUrl,
|
|
@@ -150,15 +158,10 @@ export class ProxyManager {
|
|
|
150
158
|
}
|
|
151
159
|
}
|
|
152
160
|
function readProxyFromContainer(c) {
|
|
153
|
-
const domain = [c.labels.host, c.labels.path].join("/");
|
|
161
|
+
const domain = [c.labels.host, c.labels.path].filter(Boolean).join("/");
|
|
154
162
|
const proxyOverrides = get(domain) || {};
|
|
155
163
|
return {
|
|
156
|
-
|
|
157
|
-
redirectUrl: "",
|
|
158
|
-
cors: true,
|
|
159
|
-
authorization: "",
|
|
160
|
-
preserveHost: false,
|
|
161
|
-
headers: "",
|
|
164
|
+
...emptyProxy,
|
|
162
165
|
...proxyOverrides,
|
|
163
166
|
domain,
|
|
164
167
|
target: `http://localhost:${c.ports[0].host}`,
|