@cloud-cli/px 4.2.2 → 4.2.4
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/index.d.ts +1 -1
- package/dist/proxy-manager.d.ts +1 -1
- package/dist/proxy-manager.js +24 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare const _default: {
|
|
|
5
5
|
remove(options: WithOptionalProps<DomainAndTarget>): Promise<boolean>;
|
|
6
6
|
update(options: WithOptionalProps<Proxy>): Promise<Proxy>;
|
|
7
7
|
list(filters: Partial<Proxy>): Promise<Proxy[]>;
|
|
8
|
-
get(options: DomainName): Proxy[]
|
|
8
|
+
get(options: DomainName): Promise<Proxy[]>;
|
|
9
9
|
domains(): Promise<string[]>;
|
|
10
10
|
[init](): Promise<import("@cloud-cli/proxy").ProxyServer>;
|
|
11
11
|
reload(): Promise<void>;
|
package/dist/proxy-manager.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class ProxyManager {
|
|
|
7
7
|
removeProxy(options: WithOptionalProps<DomainAndTarget>): Promise<boolean>;
|
|
8
8
|
getDomainList(): Promise<string[]>;
|
|
9
9
|
getProxyList(filters?: Partial<Proxy>): Promise<Proxy[]>;
|
|
10
|
-
getProxyListForDomain(options: WithOptionalProps<DomainName>): Proxy[]
|
|
10
|
+
getProxyListForDomain(options: WithOptionalProps<DomainName>): Promise<Proxy[]>;
|
|
11
11
|
reload(): Promise<void>;
|
|
12
12
|
getRunningContainers(): Promise<DockerContainer[]>;
|
|
13
13
|
}
|
package/dist/proxy-manager.js
CHANGED
|
@@ -97,11 +97,13 @@ export class ProxyManager {
|
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
99
|
async getDomainList() {
|
|
100
|
-
const proxies =
|
|
100
|
+
const proxies = await this.getProxyList();
|
|
101
101
|
return proxies.map((proxy) => proxy.domain);
|
|
102
102
|
}
|
|
103
103
|
async getProxyList(filters = {}) {
|
|
104
|
-
const
|
|
104
|
+
const staticRoutes = getAll();
|
|
105
|
+
const containers = await this.getRunningContainers();
|
|
106
|
+
const list = [...staticRoutes, ...containers.map(readProxyFromContainer)];
|
|
105
107
|
const keys = Object.keys(filters);
|
|
106
108
|
if (!keys.length) {
|
|
107
109
|
return list;
|
|
@@ -111,15 +113,17 @@ export class ProxyManager {
|
|
|
111
113
|
return list.filter((p) => String(p[key]).toLowerCase().includes(filter));
|
|
112
114
|
}, list);
|
|
113
115
|
}
|
|
114
|
-
getProxyListForDomain(options) {
|
|
116
|
+
async getProxyListForDomain(options) {
|
|
115
117
|
readDomain(options);
|
|
116
|
-
const all =
|
|
118
|
+
const all = await this.getProxyList();
|
|
117
119
|
return all.filter((p) => p.domain === options.domain);
|
|
118
120
|
}
|
|
119
121
|
async reload() {
|
|
120
122
|
const targets = await getAll();
|
|
123
|
+
const containers = await this.getRunningContainers();
|
|
124
|
+
const all = [...targets, ...containers.map(readProxyFromContainer)];
|
|
121
125
|
px.reset();
|
|
122
|
-
for (const t of
|
|
126
|
+
for (const t of all) {
|
|
123
127
|
const [domain, path = ""] = t.domain.split("/");
|
|
124
128
|
px.add(new ProxyEntry({
|
|
125
129
|
domain: domain,
|
|
@@ -133,18 +137,6 @@ export class ProxyManager {
|
|
|
133
137
|
preserveHost: t.preserveHost,
|
|
134
138
|
}));
|
|
135
139
|
}
|
|
136
|
-
const dockerTargets = await this.getRunningContainers();
|
|
137
|
-
for (const t of dockerTargets) {
|
|
138
|
-
if (!t.ports.length || !t.labels.host)
|
|
139
|
-
continue;
|
|
140
|
-
px.add(new ProxyEntry({
|
|
141
|
-
domain: t.labels.host,
|
|
142
|
-
path: t.labels.path || '',
|
|
143
|
-
target: `http://localhost:${t.ports[0].host}`,
|
|
144
|
-
redirectToHttps: true,
|
|
145
|
-
cors: true,
|
|
146
|
-
}));
|
|
147
|
-
}
|
|
148
140
|
px.start();
|
|
149
141
|
}
|
|
150
142
|
async getRunningContainers() {
|
|
@@ -152,9 +144,23 @@ export class ProxyManager {
|
|
|
152
144
|
const ids = ps.stdout.trim().split("\n");
|
|
153
145
|
const state = await exec("docker", ["inspect", ...ids]);
|
|
154
146
|
const json = JSON.parse(state.stdout);
|
|
155
|
-
return json
|
|
147
|
+
return json
|
|
148
|
+
.map(readDockerContainer)
|
|
149
|
+
.filter(d => d.ports.length && d.labels.host);
|
|
156
150
|
}
|
|
157
151
|
}
|
|
152
|
+
function readProxyFromContainer(c) {
|
|
153
|
+
return {
|
|
154
|
+
domain: [c.labels.host, c.labels.path].join("/"),
|
|
155
|
+
target: `http://localhost:${c.ports[0].host}`,
|
|
156
|
+
redirect: true,
|
|
157
|
+
redirectUrl: "",
|
|
158
|
+
cors: true,
|
|
159
|
+
authorization: "",
|
|
160
|
+
preserveHost: false,
|
|
161
|
+
headers: "",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
158
164
|
function readDockerContainer(d) {
|
|
159
165
|
const labels = Object.fromEntries(Object.entries(d.Config.Labels)
|
|
160
166
|
.filter(([key]) => key.startsWith("px:"))
|