@cloud-cli/px 3.1.7 → 3.2.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/README.md +9 -4
- package/dist/proxy-manager.js +4 -2
- package/dist/proxy.d.ts +2 -0
- package/dist/proxy.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,15 +19,20 @@ export default { proxy };
|
|
|
19
19
|
**Add a proxy to a local service**
|
|
20
20
|
|
|
21
21
|
```
|
|
22
|
-
cy proxy.add --domain "foo.example.com" --target "localhost:1234"
|
|
23
|
-
cy proxy.add --domain "bar.example.com/api" --target "localhost:3000"
|
|
22
|
+
cy proxy.add --domain "foo.example.com" --target "http://localhost:1234"
|
|
24
23
|
```
|
|
25
24
|
|
|
25
|
+
All available options:
|
|
26
|
+
|
|
27
|
+
- `domain`: entrypoint for reverse proxy
|
|
28
|
+
- `target`: any target for requests, can be local or remote
|
|
29
|
+
- `redirect`: if request comes as http, redirect to https
|
|
30
|
+
- `redirectUrl`: if provided, issues a `Location` header and terminates with status 302 instead of proxying a request
|
|
31
|
+
|
|
26
32
|
**Remove a proxy**
|
|
27
33
|
|
|
28
34
|
```
|
|
29
|
-
cy proxy.remove --domain "foo.example.com"
|
|
30
|
-
cy proxy.remove --domain "bar.example.com/api" --target "localhost:1234"
|
|
35
|
+
cy proxy.remove --domain "foo.example.com"
|
|
31
36
|
```
|
|
32
37
|
|
|
33
38
|
**Get details of a proxy**
|
package/dist/proxy-manager.js
CHANGED
|
@@ -9,7 +9,7 @@ export class ProxyManager {
|
|
|
9
9
|
if (!proxy.domain) {
|
|
10
10
|
return reject(domainNotSpecifiedError);
|
|
11
11
|
}
|
|
12
|
-
if (!proxy.target) {
|
|
12
|
+
if (!proxy.target && !proxy.redirectUrl) {
|
|
13
13
|
return reject(targetNotSpecifiedError);
|
|
14
14
|
}
|
|
15
15
|
const entry = new ProxyEntry({
|
|
@@ -17,9 +17,11 @@ export class ProxyManager {
|
|
|
17
17
|
target: proxy.target,
|
|
18
18
|
cors: !!proxy.cors,
|
|
19
19
|
redirect: !!proxy.redirect,
|
|
20
|
+
redirectUrl: proxy.redirectUrl || '',
|
|
20
21
|
});
|
|
21
22
|
try {
|
|
22
|
-
await entry.save();
|
|
23
|
+
const id = await entry.save();
|
|
24
|
+
entry.id = id;
|
|
23
25
|
resolve(entry);
|
|
24
26
|
}
|
|
25
27
|
catch (error) {
|
package/dist/proxy.d.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
3
|
import { Resource } from '@cloud-cli/store';
|
|
4
4
|
export declare class ProxyEntry extends Resource {
|
|
5
|
+
id: number;
|
|
5
6
|
domain: string;
|
|
6
7
|
target: string;
|
|
7
8
|
redirect: boolean;
|
|
9
|
+
redirectUrl: string;
|
|
8
10
|
cors: boolean;
|
|
9
11
|
constructor(p: Partial<ProxyEntry>);
|
|
10
12
|
}
|
package/dist/proxy.js
CHANGED
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { createServer as createHttpServer, request as httpRequest } from 'http';
|
|
8
8
|
import { createServer as createHttpsServer, request as httpsRequest } from 'https';
|
|
9
9
|
import { createSecureContext } from 'tls';
|
|
10
|
-
import { Model, Property, Query, Resource } from '@cloud-cli/store';
|
|
10
|
+
import { Model, Primary, Property, Query, Resource } from '@cloud-cli/store';
|
|
11
11
|
import { readdir, readFile, stat } from 'fs/promises';
|
|
12
12
|
import { existsSync } from 'fs';
|
|
13
13
|
import { join } from 'path';
|
|
@@ -19,6 +19,10 @@ let ProxyEntry = class ProxyEntry extends Resource {
|
|
|
19
19
|
super(p);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
+
__decorate([
|
|
23
|
+
Primary(),
|
|
24
|
+
Property(Number)
|
|
25
|
+
], ProxyEntry.prototype, "id", void 0);
|
|
22
26
|
__decorate([
|
|
23
27
|
Property(String)
|
|
24
28
|
], ProxyEntry.prototype, "domain", void 0);
|
|
@@ -28,6 +32,9 @@ __decorate([
|
|
|
28
32
|
__decorate([
|
|
29
33
|
Property(Number)
|
|
30
34
|
], ProxyEntry.prototype, "redirect", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
Property(String)
|
|
37
|
+
], ProxyEntry.prototype, "redirectUrl", void 0);
|
|
31
38
|
__decorate([
|
|
32
39
|
Property(Number)
|
|
33
40
|
], ProxyEntry.prototype, "cors", void 0);
|
|
@@ -81,6 +88,12 @@ export class ProxyServer {
|
|
|
81
88
|
res.end();
|
|
82
89
|
return;
|
|
83
90
|
}
|
|
91
|
+
if (proxyEntry.redirectUrl) {
|
|
92
|
+
res.setHeader('Location', String(proxyEntry.redirectUrl));
|
|
93
|
+
res.writeHead(302, 'Moved somewhere else');
|
|
94
|
+
res.end();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
84
97
|
if (proxyEntry.redirect && insecure) {
|
|
85
98
|
const newURL = new URL(req.url, `https://${req.headers.host}`);
|
|
86
99
|
res.setHeader('Location', String(newURL));
|