@cloud-cli/px 4.4.2 → 4.4.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 +3 -2
- package/dist/index.js +22 -12
- package/dist/proxy-manager.d.ts +2 -0
- package/dist/proxy-manager.js +28 -20
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { help, init } from
|
|
2
|
-
import { DomainAndTarget, DomainName, Proxy, WithOptionalProps } from
|
|
1
|
+
import { help, init } from '@cloud-cli/cli';
|
|
2
|
+
import { DomainAndTarget, DomainName, Proxy, WithOptionalProps } from './types.js';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
add(options: WithOptionalProps<Proxy>): Promise<Proxy>;
|
|
5
5
|
remove(options: WithOptionalProps<DomainAndTarget>): Promise<boolean>;
|
|
@@ -8,6 +8,7 @@ declare const _default: {
|
|
|
8
8
|
get(options: DomainName): Promise<Proxy[]>;
|
|
9
9
|
domains(): Promise<string[]>;
|
|
10
10
|
reload(): Promise<void>;
|
|
11
|
+
restart(): Promise<void>;
|
|
11
12
|
[init](): Promise<import("@cloud-cli/proxy").ProxyServer>;
|
|
12
13
|
[help](): string;
|
|
13
14
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { help, init, logInfo } from
|
|
2
|
-
import { ProxyManager } from
|
|
1
|
+
import { help, init, logInfo } from '@cloud-cli/cli';
|
|
2
|
+
import { ProxyManager } from './proxy-manager.js';
|
|
3
3
|
const manager = new ProxyManager();
|
|
4
4
|
export default {
|
|
5
5
|
async add(options) {
|
|
@@ -21,25 +21,35 @@ export default {
|
|
|
21
21
|
return manager.getDomainList();
|
|
22
22
|
},
|
|
23
23
|
async reload() {
|
|
24
|
-
logInfo(
|
|
24
|
+
logInfo('Reloading proxy configuration');
|
|
25
25
|
return await manager.reload();
|
|
26
26
|
},
|
|
27
|
+
async restart() {
|
|
28
|
+
logInfo('Restarting server');
|
|
29
|
+
return await manager.restart();
|
|
30
|
+
},
|
|
27
31
|
async [init]() {
|
|
28
|
-
await manager.
|
|
32
|
+
await manager.restart();
|
|
29
33
|
return manager.server;
|
|
30
34
|
},
|
|
31
35
|
[help]() {
|
|
32
36
|
return `Manages reverse proxy entries
|
|
33
37
|
|
|
34
38
|
Available commands:
|
|
35
|
-
px.add
|
|
36
|
-
px.
|
|
37
|
-
|
|
38
|
-
px.
|
|
39
|
-
|
|
40
|
-
px.
|
|
41
|
-
|
|
39
|
+
px.add
|
|
40
|
+
px.update
|
|
41
|
+
--domain <domain> <proxy options>
|
|
42
|
+
px.remove
|
|
43
|
+
--domain <domain>
|
|
44
|
+
px.list
|
|
45
|
+
[--domain <domain>] <proxy options>
|
|
46
|
+
px.get
|
|
47
|
+
--domain <domain>
|
|
48
|
+
px.domains
|
|
49
|
+
px.reload
|
|
50
|
+
px.restart
|
|
42
51
|
|
|
43
|
-
Proxy options:
|
|
52
|
+
Proxy options:
|
|
53
|
+
--target <url> [--cors] [--redirect] [--preserveHost] [--redirectUrl <url>] [--headers <headers>] [--authorization <value>]`;
|
|
44
54
|
},
|
|
45
55
|
};
|
package/dist/proxy-manager.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ 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
|
+
restart(): Promise<void>;
|
|
12
13
|
reload(): Promise<void>;
|
|
14
|
+
private loadProxy;
|
|
13
15
|
getRunningContainers(): Promise<DockerContainer[]>;
|
|
14
16
|
}
|
package/dist/proxy-manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getStorage, getConfig } from '@cloud-cli/cli';
|
|
1
|
+
import { getStorage, getConfig, logInfo, logError } from '@cloud-cli/cli';
|
|
2
2
|
import { ProxyEntry, ProxyServer, ProxySettings } from '@cloud-cli/proxy';
|
|
3
3
|
import { exec } from '@cloud-cli/exec';
|
|
4
4
|
const defaultOptions = {
|
|
@@ -125,29 +125,37 @@ export class ProxyManager {
|
|
|
125
125
|
const all = await this.getProxyListWithContainers();
|
|
126
126
|
return all.filter((p) => p.domain.includes(options.domain));
|
|
127
127
|
}
|
|
128
|
+
async restart() {
|
|
129
|
+
await px.reset();
|
|
130
|
+
await px.start();
|
|
131
|
+
await this.reload();
|
|
132
|
+
}
|
|
128
133
|
async reload() {
|
|
129
134
|
const all = await this.getProxyListWithContainers();
|
|
130
|
-
px.
|
|
135
|
+
px.resetProxies();
|
|
131
136
|
for (const t of all) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
137
|
+
this.loadProxy(t);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
loadProxy(t) {
|
|
141
|
+
try {
|
|
142
|
+
const [domain, path = ''] = t.domain.split('/');
|
|
143
|
+
px.add(new ProxyEntry({
|
|
144
|
+
domain,
|
|
145
|
+
path,
|
|
146
|
+
target: t.target,
|
|
147
|
+
redirectToHttps: t.redirect,
|
|
148
|
+
redirectToUrl: t.redirectUrl,
|
|
149
|
+
cors: t.cors,
|
|
150
|
+
headers: t.headers,
|
|
151
|
+
authorization: t.authorization,
|
|
152
|
+
preserveHost: t.preserveHost,
|
|
153
|
+
}));
|
|
154
|
+
logInfo(` ${t.domain} => ${t.target || t.redirectUrl}`);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
logError(`Error adding proxy for ${t.domain}: ${error}`);
|
|
149
158
|
}
|
|
150
|
-
px.start();
|
|
151
159
|
}
|
|
152
160
|
async getRunningContainers() {
|
|
153
161
|
const ps = await exec('docker', ['ps', '-aq']);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/px",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.4",
|
|
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.
|
|
31
|
+
"@cloud-cli/proxy": "^1.2.10",
|
|
32
32
|
"@cloud-cli/exec": "^1.2.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|