@cloud-cli/px 3.2.2 → 3.3.1
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 -0
- package/dist/proxy.js +9 -7
- 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
|
@@ -28,6 +28,18 @@ export class ProxyManager {
|
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
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
|
+
}
|
|
31
43
|
removeProxy(options) {
|
|
32
44
|
return new Promise(async (resolve, reject) => {
|
|
33
45
|
if (!options.domain) {
|
package/dist/proxy.js
CHANGED
|
@@ -105,8 +105,8 @@ export class ProxyServer {
|
|
|
105
105
|
const url = new URL(req.url, target);
|
|
106
106
|
const isCorsPreflight = req.method === 'OPTIONS' && proxyEntry.cors;
|
|
107
107
|
if (isCorsPreflight) {
|
|
108
|
-
|
|
109
|
-
res.writeHead(204, '
|
|
108
|
+
setCorsHeaders(req, res);
|
|
109
|
+
res.writeHead(204, { 'Content-Length': '0' });
|
|
110
110
|
res.end();
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
@@ -120,7 +120,7 @@ export class ProxyServer {
|
|
|
120
120
|
setHeaders(proxyRes, res);
|
|
121
121
|
const isCorsSimple = req.method !== 'OPTIONS' && proxyEntry.cors && req.headers.origin;
|
|
122
122
|
if (isCorsSimple) {
|
|
123
|
-
|
|
123
|
+
setCorsHeaders(req, res);
|
|
124
124
|
}
|
|
125
125
|
res.writeHead(proxyRes.statusCode, proxyRes.statusMessage);
|
|
126
126
|
proxyRes.on('data', (chunk) => res.write(chunk));
|
|
@@ -179,9 +179,11 @@ function getHost(string) {
|
|
|
179
179
|
const url = new URL(string);
|
|
180
180
|
return url.hostname + (url.port ? ':' + url.port : '');
|
|
181
181
|
}
|
|
182
|
-
function
|
|
183
|
-
const corsOrigin = new URL(req.headers.origin);
|
|
184
|
-
res.setHeader('
|
|
182
|
+
function setCorsHeaders(req, res) {
|
|
183
|
+
const corsOrigin = new URL(req.headers.origin).origin;
|
|
184
|
+
res.setHeader('Vary', 'Origin');
|
|
185
|
+
res.setHeader('Access-Control-Allow-Origin', corsOrigin);
|
|
185
186
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
186
|
-
res.setHeader('Access-Control-Allow-Methods', '
|
|
187
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
|
|
188
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
187
189
|
}
|