@cloud-cli/px 3.2.1 → 3.3.0
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 +2 -0
- package/dist/index.js +6 -1
- package/dist/proxy-manager.d.ts +1 -0
- package/dist/proxy-manager.js +12 -4
- package/dist/proxy.js +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DomainAndTarget, Domain } from './proxy-manager.js';
|
|
|
3
3
|
import { ProxyEntry } from './proxy.js';
|
|
4
4
|
declare function add(options: ProxyEntry): Promise<unknown>;
|
|
5
5
|
declare function remove(options: DomainAndTarget): Promise<unknown>;
|
|
6
|
+
declare function update(options: ProxyEntry): Promise<boolean>;
|
|
6
7
|
declare function list(): Promise<ProxyEntry[]>;
|
|
7
8
|
declare function get(options: Domain): Promise<ProxyEntry[]>;
|
|
8
9
|
declare function domains(): Promise<string[]>;
|
|
@@ -12,6 +13,7 @@ declare const _default: {
|
|
|
12
13
|
remove: typeof remove;
|
|
13
14
|
list: typeof list;
|
|
14
15
|
get: typeof get;
|
|
16
|
+
update: typeof update;
|
|
15
17
|
domains: typeof domains;
|
|
16
18
|
reload: typeof reload;
|
|
17
19
|
[init]: typeof reload;
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,11 @@ async function remove(options) {
|
|
|
14
14
|
px.reload();
|
|
15
15
|
return removed;
|
|
16
16
|
}
|
|
17
|
+
async function update(options) {
|
|
18
|
+
const output = await manager.updateProxy(options);
|
|
19
|
+
px.reload();
|
|
20
|
+
return output;
|
|
21
|
+
}
|
|
17
22
|
function list() {
|
|
18
23
|
return manager.getProxyList();
|
|
19
24
|
}
|
|
@@ -28,4 +33,4 @@ async function reload() {
|
|
|
28
33
|
await Resource.create(ProxyEntry);
|
|
29
34
|
return px.start();
|
|
30
35
|
}
|
|
31
|
-
export default { add, remove, list, get, domains, reload, [init]: reload };
|
|
36
|
+
export default { add, remove, list, get, update, domains, reload, [init]: reload };
|
package/dist/proxy-manager.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ type ClassProperties<T> = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare class ProxyManager {
|
|
15
15
|
addProxy(proxy: ClassProperties<ProxyEntry>): Promise<unknown>;
|
|
16
|
+
updateProxy(options: ClassProperties<ProxyEntry>): Promise<boolean>;
|
|
16
17
|
removeProxy(options: DomainAndTarget): Promise<unknown>;
|
|
17
18
|
getDomainList(): Promise<string[]>;
|
|
18
19
|
getProxyList(): Promise<ProxyEntry[]>;
|
package/dist/proxy-manager.js
CHANGED
|
@@ -2,7 +2,6 @@ import { Query, Resource } from '@cloud-cli/store';
|
|
|
2
2
|
import { ProxyEntry } from './proxy.js';
|
|
3
3
|
const domainNotSpecifiedError = new Error('Domain not specified');
|
|
4
4
|
const targetNotSpecifiedError = new Error('Target not specified');
|
|
5
|
-
const notFoundError = new Error('Proxy not found');
|
|
6
5
|
export class ProxyManager {
|
|
7
6
|
addProxy(proxy) {
|
|
8
7
|
return new Promise(async (resolve, reject) => {
|
|
@@ -29,6 +28,18 @@ export class ProxyManager {
|
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
30
|
}
|
|
31
|
+
async updateProxy(options) {
|
|
32
|
+
const query = new Query().where('domain').is(options.domain);
|
|
33
|
+
const proxies = await Resource.find(ProxyEntry, query);
|
|
34
|
+
if (!proxies.length) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
for (const proxy of proxies) {
|
|
38
|
+
['target', 'cors', 'redirect', 'redirectUrl'].forEach(p => p in options && (proxy[p] = options[p]));
|
|
39
|
+
await proxy.save();
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
32
43
|
removeProxy(options) {
|
|
33
44
|
return new Promise(async (resolve, reject) => {
|
|
34
45
|
if (!options.domain) {
|
|
@@ -39,9 +50,6 @@ export class ProxyManager {
|
|
|
39
50
|
query.where('target').is(options.target);
|
|
40
51
|
}
|
|
41
52
|
const proxy = await Resource.find(ProxyEntry, query);
|
|
42
|
-
if (!proxy.length) {
|
|
43
|
-
return reject(notFoundError);
|
|
44
|
-
}
|
|
45
53
|
try {
|
|
46
54
|
for (const p of proxy) {
|
|
47
55
|
await p.remove();
|
package/dist/proxy.js
CHANGED
|
@@ -184,4 +184,5 @@ function setCorsOriginHeader(req, res) {
|
|
|
184
184
|
res.setHeader('Access-Control-Allow-Origin', corsOrigin.origin);
|
|
185
185
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
186
186
|
res.setHeader('Access-Control-Allow-Methods', '*');
|
|
187
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
187
188
|
}
|