@cloud-cli/px 3.4.2 → 3.5.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/README.md CHANGED
@@ -83,8 +83,10 @@ CORS handling on proxy level is convenient, **but a security risk**. Beware:
83
83
  - All origins are allowed, all common methods and headers, and credentials are enabled.
84
84
  - In case of an `OPTIONS` request, if coming via CORS (a preflight), an empty response will be send and the request ends before calling the proxied target.
85
85
 
86
- Every request has 2 additional headers:
86
+ Every request has additional headers:
87
87
 
88
88
  - x-forwarded-for: the host of the original request.
89
89
  If a proxy is from 'https://foo.example.com' to 'http://localhost:1234', the header will be 'foo.example.com'
90
- - x-forwarded-proto: 'http:' or 'https:', depends on the original request
90
+ - x-forwarded-proto: 'http' or 'https', depends on the original request
91
+ - forwarded: the standard header with the same information as the other two above
92
+
@@ -1,6 +1,7 @@
1
1
  import { ProxyEntry } from './proxy.js';
2
2
  export interface Domain {
3
3
  domain: string;
4
+ host?: string;
4
5
  }
5
6
  export interface DomainAndTarget extends Domain {
6
7
  target: string;
@@ -12,8 +13,12 @@ type ClassProperties<T> = {
12
13
  [K in KeysOf<T>]: T[K] extends never ? never : T[K];
13
14
  };
14
15
  export declare class ProxyManager {
15
- addProxy(proxy: ClassProperties<ProxyEntry>): Promise<unknown>;
16
- updateProxy(options: ClassProperties<ProxyEntry>): Promise<boolean>;
16
+ addProxy(proxy: ClassProperties<ProxyEntry> & {
17
+ host?: string;
18
+ }): Promise<unknown>;
19
+ updateProxy(options: ClassProperties<ProxyEntry> & {
20
+ host?: string;
21
+ }): Promise<boolean>;
17
22
  removeProxy(options: DomainAndTarget): Promise<unknown>;
18
23
  getDomainList(): Promise<string[]>;
19
24
  getProxyList(): Promise<ProxyEntry[]>;
@@ -5,14 +5,14 @@ const targetNotSpecifiedError = new Error('Target not specified');
5
5
  export class ProxyManager {
6
6
  addProxy(proxy) {
7
7
  return new Promise(async (resolve, reject) => {
8
- if (!proxy.domain) {
8
+ if (!proxy.domain && !proxy.host) {
9
9
  return reject(domainNotSpecifiedError);
10
10
  }
11
11
  if (!proxy.target && !proxy.redirectUrl) {
12
12
  return reject(targetNotSpecifiedError);
13
13
  }
14
14
  const entry = new ProxyEntry({
15
- domain: proxy.domain,
15
+ domain: proxy.domain || proxy.host,
16
16
  target: proxy.target,
17
17
  cors: !!proxy.cors,
18
18
  redirect: !!proxy.redirect,
@@ -29,7 +29,7 @@ export class ProxyManager {
29
29
  });
30
30
  }
31
31
  async updateProxy(options) {
32
- const query = new Query().where('domain').is(options.domain);
32
+ const query = new Query().where('domain').is(options.domain || options.host);
33
33
  const proxies = await Resource.find(ProxyEntry, query);
34
34
  if (!proxies.length) {
35
35
  return false;
@@ -42,10 +42,10 @@ export class ProxyManager {
42
42
  }
43
43
  removeProxy(options) {
44
44
  return new Promise(async (resolve, reject) => {
45
- if (!options.domain) {
45
+ if (!options.domain && !options.host) {
46
46
  return reject(domainNotSpecifiedError);
47
47
  }
48
- const query = new Query().where('domain').is(options.domain);
48
+ const query = new Query().where('domain').is(options.domain || options.host);
49
49
  if (options.target) {
50
50
  query.where('target').is(options.target);
51
51
  }
@@ -69,6 +69,6 @@ export class ProxyManager {
69
69
  return Resource.find(ProxyEntry, new Query());
70
70
  }
71
71
  getProxyListForDomain(options) {
72
- return Resource.find(ProxyEntry, new Query().where('domain').is(options.domain));
72
+ return Resource.find(ProxyEntry, new Query().where('domain').is(options.domain || options.host));
73
73
  }
74
74
  }
package/dist/proxy.js CHANGED
@@ -113,7 +113,7 @@ export class ProxyServer {
113
113
  proxyRequest.setHeader('host', this.getHost(target));
114
114
  proxyRequest.setHeader('x-forwarded-for', req.headers.host);
115
115
  proxyRequest.setHeader('x-forwarded-proto', insecure ? 'http' : 'https');
116
- proxyRequest.setHeader('forwarded', 'host=' + req.headers.host + ';proto=' + insecure ? 'http' : 'https');
116
+ proxyRequest.setHeader('forwarded', 'host=' + req.headers.host + ';proto=' + (insecure ? 'http' : 'https'));
117
117
  req.on('data', (chunk) => proxyRequest.write(chunk));
118
118
  req.on('end', () => proxyRequest.end());
119
119
  proxyRequest.on('error', (error) => this.handleError(error, res));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/px",
3
- "version": "3.4.2",
3
+ "version": "3.5.0",
4
4
  "description": "Reverse Proxy",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",