@cloud-cli/px 4.4.1 → 4.4.2

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.
@@ -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 = {}) {
@@ -132,33 +129,36 @@ export class ProxyManager {
132
129
  const all = await this.getProxyListWithContainers();
133
130
  px.reset();
134
131
  for (const t of all) {
135
- const [domain, path = ""] = t.domain.split("/");
136
- px.add(new ProxyEntry({
137
- domain,
138
- path,
139
- target: t.target,
140
- redirectToHttps: t.redirect,
141
- redirectToUrl: t.redirectUrl,
142
- cors: t.cors,
143
- headers: t.headers,
144
- authorization: t.authorization,
145
- preserveHost: t.preserveHost,
146
- }));
132
+ try {
133
+ const [domain, path = ''] = t.domain.split('/');
134
+ px.add(new ProxyEntry({
135
+ domain,
136
+ path,
137
+ target: t.target,
138
+ redirectToHttps: t.redirect,
139
+ redirectToUrl: t.redirectUrl,
140
+ cors: t.cors,
141
+ headers: t.headers,
142
+ authorization: t.authorization,
143
+ preserveHost: t.preserveHost,
144
+ }));
145
+ }
146
+ catch (error) {
147
+ console.log(`Error adding proxy for ${t.domain}:`, error);
148
+ }
147
149
  }
148
150
  px.start();
149
151
  }
150
152
  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]);
153
+ const ps = await exec('docker', ['ps', '-aq']);
154
+ const ids = ps.stdout.trim().split('\n');
155
+ const state = await exec('docker', ['inspect', ...ids]);
154
156
  const json = JSON.parse(state.stdout);
155
- return json
156
- .map(readDockerContainer)
157
- .filter(d => d.ports.length && d.labels.host);
157
+ return json.map(readDockerContainer).filter((d) => d.ports.length && d.labels.host);
158
158
  }
159
159
  }
160
160
  function readProxyFromContainer(c) {
161
- const domain = [c.labels.host, c.labels.path].filter(Boolean).join("/");
161
+ const domain = [c.labels.host, c.labels.path].filter(Boolean).join('/');
162
162
  const proxyOverrides = get(domain) || {};
163
163
  return {
164
164
  ...emptyProxy,
@@ -169,8 +169,8 @@ function readProxyFromContainer(c) {
169
169
  }
170
170
  function readDockerContainer(d) {
171
171
  const labels = Object.fromEntries(Object.entries(d.Config.Labels || {})
172
- .filter(([key]) => key.startsWith("px:"))
173
- .map(([key, value]) => [key.replace("px:", ""), value]));
172
+ .filter(([key]) => key.startsWith('px:'))
173
+ .map(([key, value]) => [key.replace('px:', ''), value]));
174
174
  return {
175
175
  id: d.Id,
176
176
  image: d.Image,
@@ -178,7 +178,7 @@ function readDockerContainer(d) {
178
178
  name: d.Name,
179
179
  labels: labels,
180
180
  ports: Object.entries(d.HostConfig.PortBindings || {}).map(([port, pb]) => ({
181
- container: Number(port.replace(/\D+/, "")),
181
+ container: Number(port.replace(/\D+/, '')),
182
182
  host: Number(pb[0].HostPort),
183
183
  })),
184
184
  };
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.2",
4
4
  "description": "Reverse Proxy",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",