@cloud-cli/px 4.4.1 → 4.4.3

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.
@@ -9,6 +9,9 @@ export declare class ProxyManager {
9
9
  getProxyListWithContainers(): Promise<Proxy[]>;
10
10
  getProxyList(filters?: Partial<Proxy>): Promise<Proxy[]>;
11
11
  getProxyListForDomain(options: WithOptionalProps<DomainName>): Promise<Proxy[]>;
12
- reload(): Promise<void>;
12
+ reload(options?: {
13
+ servers?: Boolean;
14
+ }): Promise<void>;
15
+ private loadProxy;
13
16
  getRunningContainers(): Promise<DockerContainer[]>;
14
17
  }
@@ -32,7 +32,7 @@ const readDomain = (options) => {
32
32
  options.domain = options.domain || options.host || options._[0];
33
33
  };
34
34
  const numberRe = /^[0-9]+$/;
35
- const readOption = value => {
35
+ const readOption = (value) => {
36
36
  switch (true) {
37
37
  case value === 'true':
38
38
  return true;
@@ -105,11 +105,8 @@ export class ProxyManager {
105
105
  async getProxyListWithContainers() {
106
106
  const staticRoutes = getAll();
107
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
- ];
108
+ const containerDomains = containers.map((c) => c.domain.split('/')[0]);
109
+ const list = [...staticRoutes.filter((t) => !containerDomains.includes(t.domain)), ...containers];
113
110
  return list;
114
111
  }
115
112
  async getProxyList(filters = {}) {
@@ -128,11 +125,24 @@ export class ProxyManager {
128
125
  const all = await this.getProxyListWithContainers();
129
126
  return all.filter((p) => p.domain.includes(options.domain));
130
127
  }
131
- async reload() {
128
+ async reload(options = {}) {
132
129
  const all = await this.getProxyListWithContainers();
133
- px.reset();
130
+ if (options.servers) {
131
+ px.reset();
132
+ }
133
+ else {
134
+ px.resetProxies();
135
+ }
134
136
  for (const t of all) {
135
- const [domain, path = ""] = t.domain.split("/");
137
+ this.loadProxy(t);
138
+ }
139
+ if (options.servers) {
140
+ px.start();
141
+ }
142
+ }
143
+ loadProxy(t) {
144
+ try {
145
+ const [domain, path = ''] = t.domain.split('/');
136
146
  px.add(new ProxyEntry({
137
147
  domain,
138
148
  path,
@@ -145,20 +155,20 @@ export class ProxyManager {
145
155
  preserveHost: t.preserveHost,
146
156
  }));
147
157
  }
148
- px.start();
158
+ catch (error) {
159
+ console.log(`Error adding proxy for ${t.domain}:`, error);
160
+ }
149
161
  }
150
162
  async getRunningContainers() {
151
- const ps = await exec("docker", ["ps", "-aq"]);
152
- const ids = ps.stdout.trim().split("\n");
153
- const state = await exec("docker", ["inspect", ...ids]);
163
+ const ps = await exec('docker', ['ps', '-aq']);
164
+ const ids = ps.stdout.trim().split('\n');
165
+ const state = await exec('docker', ['inspect', ...ids]);
154
166
  const json = JSON.parse(state.stdout);
155
- return json
156
- .map(readDockerContainer)
157
- .filter(d => d.ports.length && d.labels.host);
167
+ return json.map(readDockerContainer).filter((d) => d.ports.length && d.labels.host);
158
168
  }
159
169
  }
160
170
  function readProxyFromContainer(c) {
161
- const domain = [c.labels.host, c.labels.path].filter(Boolean).join("/");
171
+ const domain = [c.labels.host, c.labels.path].filter(Boolean).join('/');
162
172
  const proxyOverrides = get(domain) || {};
163
173
  return {
164
174
  ...emptyProxy,
@@ -169,8 +179,8 @@ function readProxyFromContainer(c) {
169
179
  }
170
180
  function readDockerContainer(d) {
171
181
  const labels = Object.fromEntries(Object.entries(d.Config.Labels || {})
172
- .filter(([key]) => key.startsWith("px:"))
173
- .map(([key, value]) => [key.replace("px:", ""), value]));
182
+ .filter(([key]) => key.startsWith('px:'))
183
+ .map(([key, value]) => [key.replace('px:', ''), value]));
174
184
  return {
175
185
  id: d.Id,
176
186
  image: d.Image,
@@ -178,7 +188,7 @@ function readDockerContainer(d) {
178
188
  name: d.Name,
179
189
  labels: labels,
180
190
  ports: Object.entries(d.HostConfig.PortBindings || {}).map(([port, pb]) => ({
181
- container: Number(port.replace(/\D+/, "")),
191
+ container: Number(port.replace(/\D+/, '')),
182
192
  host: Number(pb[0].HostPort),
183
193
  })),
184
194
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/px",
3
- "version": "4.4.1",
3
+ "version": "4.4.3",
4
4
  "description": "Reverse Proxy",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@cloud-cli/proxy": "^1.2.0",
31
+ "@cloud-cli/proxy": "^1.2.10",
32
32
  "@cloud-cli/exec": "^1.2.0"
33
33
  },
34
34
  "peerDependencies": {