@cloud-cli/px 4.2.5 → 4.2.7

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.
@@ -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>;
@@ -100,10 +100,18 @@ export class ProxyManager {
100
100
  const proxies = await this.getProxyList();
101
101
  return proxies.map((proxy) => proxy.domain);
102
102
  }
103
- async getProxyList(filters = {}) {
103
+ async getProxyListWithContainers() {
104
104
  const staticRoutes = getAll();
105
- const containers = await this.getRunningContainers();
106
- const list = [...staticRoutes, ...containers.map(readProxyFromContainer)];
105
+ const containers = (await this.getRunningContainers()).map(readProxyFromContainer);
106
+ const containerDomains = containers.map(c => c.domain.split('/')[0]);
107
+ const list = [
108
+ ...staticRoutes.filter(t => !containerDomains.includes(t.domain)),
109
+ ...containers,
110
+ ];
111
+ return list;
112
+ }
113
+ async getProxyList(filters = {}) {
114
+ const list = await this.getProxyListWithContainers();
107
115
  const keys = Object.keys(filters);
108
116
  if (!keys.length) {
109
117
  return list;
@@ -119,9 +127,7 @@ export class ProxyManager {
119
127
  return all.filter((p) => p.domain === options.domain);
120
128
  }
121
129
  async reload() {
122
- const targets = await getAll();
123
- const containers = await this.getRunningContainers();
124
- const all = [...targets, ...containers.map(readProxyFromContainer)];
130
+ const all = await this.getProxyListWithContainers();
125
131
  px.reset();
126
132
  for (const t of all) {
127
133
  const [domain, path = ""] = t.domain.split("/");
@@ -165,7 +171,7 @@ function readProxyFromContainer(c) {
165
171
  };
166
172
  }
167
173
  function readDockerContainer(d) {
168
- const labels = Object.fromEntries(Object.entries(d.Config.Labels)
174
+ const labels = Object.fromEntries(Object.entries(d.Config.Labels || {})
169
175
  .filter(([key]) => key.startsWith("px:"))
170
176
  .map(([key, value]) => [key.replace("px:", ""), value]));
171
177
  return {
@@ -174,7 +180,7 @@ function readDockerContainer(d) {
174
180
  state: d.State.Status,
175
181
  name: d.Name,
176
182
  labels: labels,
177
- ports: Object.entries(d.HostConfig.PortBindings).map(([port, pb]) => ({
183
+ ports: Object.entries(d.HostConfig.PortBindings || {}).map(([port, pb]) => ({
178
184
  container: Number(port.replace(/\D+/, "")),
179
185
  host: Number(pb[0].HostPort),
180
186
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/px",
3
- "version": "4.2.5",
3
+ "version": "4.2.7",
4
4
  "description": "Reverse Proxy",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",