@gasket/plugin-https-proxy 7.4.1 → 7.4.2
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/EXAMPLES.md +120 -0
- package/lib/index.d.ts +89 -4
- package/package.json +9 -8
package/EXAMPLES.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @gasket/plugin-https-proxy Examples
|
|
2
|
+
|
|
3
|
+
This document provides working examples for all exported interfaces from `@gasket/plugin-https-proxy`.
|
|
4
|
+
|
|
5
|
+
## Plugin Configuration
|
|
6
|
+
|
|
7
|
+
### Basic Setup
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
// gasket.js
|
|
11
|
+
import { makeGasket } from '@gasket/core';
|
|
12
|
+
import pluginHttpsProxy from '@gasket/plugin-https-proxy';
|
|
13
|
+
|
|
14
|
+
export default makeGasket({
|
|
15
|
+
plugins: [
|
|
16
|
+
pluginHttpsProxy
|
|
17
|
+
],
|
|
18
|
+
httpsProxy: {
|
|
19
|
+
protocol: 'https',
|
|
20
|
+
hostname: 'localhost',
|
|
21
|
+
port: 8443,
|
|
22
|
+
target: {
|
|
23
|
+
host: 'localhost',
|
|
24
|
+
port: 3000
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Advanced Configuration with SNI
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// gasket.js
|
|
34
|
+
import { makeGasket } from '@gasket/core';
|
|
35
|
+
import pluginHttpsProxy from '@gasket/plugin-https-proxy';
|
|
36
|
+
import tls from 'tls';
|
|
37
|
+
import fs from 'fs';
|
|
38
|
+
|
|
39
|
+
export default makeGasket({
|
|
40
|
+
plugins: [
|
|
41
|
+
pluginHttpsProxy
|
|
42
|
+
],
|
|
43
|
+
httpsProxy: {
|
|
44
|
+
protocol: 'https',
|
|
45
|
+
hostname: 'example.com',
|
|
46
|
+
port: 443,
|
|
47
|
+
target: {
|
|
48
|
+
host: 'localhost',
|
|
49
|
+
port: 3000
|
|
50
|
+
},
|
|
51
|
+
ssl: {
|
|
52
|
+
SNICallback: (hostname, cb) => {
|
|
53
|
+
const ctx = tls.createSecureContext({
|
|
54
|
+
key: fs.readFileSync(`./certs/${hostname}.key`),
|
|
55
|
+
cert: fs.readFileSync(`./certs/${hostname}.crt`)
|
|
56
|
+
});
|
|
57
|
+
cb(null, ctx);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
xfwd: true,
|
|
61
|
+
ws: true
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Actions
|
|
67
|
+
|
|
68
|
+
### startProxyServer
|
|
69
|
+
|
|
70
|
+
Start the HTTPS proxy server with configured settings:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
// server.js
|
|
74
|
+
import gasket from './gasket.js';
|
|
75
|
+
|
|
76
|
+
gasket.actions.startProxyServer();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Lifecycle Hooks
|
|
80
|
+
|
|
81
|
+
### prebootHttpsProxy
|
|
82
|
+
|
|
83
|
+
Execute operations before the proxy server starts:
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
// my-plugin.js
|
|
87
|
+
export default {
|
|
88
|
+
name: 'my-proxy-plugin',
|
|
89
|
+
hooks: {
|
|
90
|
+
prebootHttpsProxy: async function(gasket) {
|
|
91
|
+
// Load SSL certificates
|
|
92
|
+
gasket.logger.info('Loading SSL certificates...');
|
|
93
|
+
await loadCertificates();
|
|
94
|
+
|
|
95
|
+
// Initialize connection pools
|
|
96
|
+
gasket.logger.info('Initializing connection pools...');
|
|
97
|
+
await initializeConnectionPools();
|
|
98
|
+
|
|
99
|
+
// Set up health check endpoints
|
|
100
|
+
gasket.logger.info('Setting up health checks...');
|
|
101
|
+
await setupHealthChecks();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
async function loadCertificates() {
|
|
107
|
+
// Certificate loading logic
|
|
108
|
+
return new Promise(resolve => setTimeout(resolve, 100));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function initializeConnectionPools() {
|
|
112
|
+
// Connection pool initialization
|
|
113
|
+
return new Promise(resolve => setTimeout(resolve, 50));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function setupHealthChecks() {
|
|
117
|
+
// Health check setup
|
|
118
|
+
return new Promise(resolve => setTimeout(resolve, 25));
|
|
119
|
+
}
|
|
120
|
+
```
|
package/lib/index.d.ts
CHANGED
|
@@ -1,16 +1,101 @@
|
|
|
1
1
|
import type { Plugin, MaybeAsync } from '@gasket/core';
|
|
2
|
-
import type { ServerOptions as ProxyServerOptions } from 'http-proxy';
|
|
3
|
-
import ProxyServer from 'http-proxy';
|
|
4
2
|
import type { RequireAtLeastOne } from '@gasket/plugin-https';
|
|
3
|
+
import type { Url } from 'url';
|
|
4
|
+
import type { Stream } from 'stream';
|
|
5
|
+
import ProxyServer from 'http-proxy';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* http-proxy does not export types.
|
|
9
|
+
* Any Proxy* types have been lifted from @types/http-proxy
|
|
10
|
+
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/http-proxy/index.d.ts
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
interface ProxyTargetDetailed {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
protocol?: string | undefined;
|
|
17
|
+
hostname?: string | undefined;
|
|
18
|
+
socketPath?: string | undefined;
|
|
19
|
+
key?: string | undefined;
|
|
20
|
+
passphrase?: string | undefined;
|
|
21
|
+
pfx?: Buffer | string | undefined;
|
|
22
|
+
cert?: string | undefined;
|
|
23
|
+
ca?: string | undefined;
|
|
24
|
+
ciphers?: string | undefined;
|
|
25
|
+
secureProtocol?: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type ProxyTargetUrl = string | Partial<Url>;
|
|
29
|
+
type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
|
|
30
|
+
|
|
31
|
+
interface ProxyServerOptions {
|
|
32
|
+
/** URL string to be parsed with the url module. */
|
|
33
|
+
target?: ProxyTarget | undefined;
|
|
34
|
+
/** URL string to be parsed with the url module. */
|
|
35
|
+
forward?: ProxyTargetUrl | undefined;
|
|
36
|
+
/** Object to be passed to http(s).request. */
|
|
37
|
+
agent?: any;
|
|
38
|
+
/** Object to be passed to https.createServer(). */
|
|
39
|
+
ssl?: any;
|
|
40
|
+
/** If you want to proxy websockets. */
|
|
41
|
+
ws?: boolean | undefined;
|
|
42
|
+
/** Adds x- forward headers. */
|
|
43
|
+
xfwd?: boolean | undefined;
|
|
44
|
+
/** Verify SSL certificate. */
|
|
45
|
+
secure?: boolean | undefined;
|
|
46
|
+
/** Explicitly specify if we are proxying to another proxy. */
|
|
47
|
+
toProxy?: boolean | undefined;
|
|
48
|
+
/** Specify whether you want to prepend the target's path to the proxy path. */
|
|
49
|
+
prependPath?: boolean | undefined;
|
|
50
|
+
/** Specify whether you want to ignore the proxy path of the incoming request. */
|
|
51
|
+
ignorePath?: boolean | undefined;
|
|
52
|
+
/** Local interface string to bind for outgoing connections. */
|
|
53
|
+
localAddress?: string | undefined;
|
|
54
|
+
/** Changes the origin of the host header to the target URL. */
|
|
55
|
+
changeOrigin?: boolean | undefined;
|
|
56
|
+
/** specify whether you want to keep letter case of response header key */
|
|
57
|
+
preserveHeaderKeyCase?: boolean | undefined;
|
|
58
|
+
/** Basic authentication i.e. 'user:password' to compute an Authorization header. */
|
|
59
|
+
auth?: string | undefined;
|
|
60
|
+
/** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
|
|
61
|
+
hostRewrite?: string | undefined;
|
|
62
|
+
/** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
|
|
63
|
+
autoRewrite?: boolean | undefined;
|
|
64
|
+
/** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
|
|
65
|
+
protocolRewrite?: string | undefined;
|
|
66
|
+
/** rewrites domain of set-cookie headers. */
|
|
67
|
+
cookieDomainRewrite?: false | string | { [oldDomain: string]: string } | undefined;
|
|
68
|
+
/** rewrites path of set-cookie headers. Default: false */
|
|
69
|
+
cookiePathRewrite?: false | string | { [oldPath: string]: string } | undefined;
|
|
70
|
+
/** object with extra headers to be added to target requests. */
|
|
71
|
+
headers?: { [header: string]: string } | undefined;
|
|
72
|
+
/** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
|
|
73
|
+
proxyTimeout?: number | undefined;
|
|
74
|
+
/** Timeout (in milliseconds) for incoming requests */
|
|
75
|
+
timeout?: number | undefined;
|
|
76
|
+
/** Specify whether you want to follow redirects. Default: false */
|
|
77
|
+
followRedirects?: boolean | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* If set to true, none of the webOutgoing passes are called and it's your responsibility
|
|
80
|
+
* to appropriately return the response by listening and acting on the proxyRes event
|
|
81
|
+
*/
|
|
82
|
+
selfHandleResponse?: boolean | undefined;
|
|
83
|
+
/** Buffer */
|
|
84
|
+
buffer?: Stream | undefined;
|
|
85
|
+
/** Explicitly set the method type of the ProxyReq */
|
|
86
|
+
method?: string | undefined;
|
|
87
|
+
}
|
|
5
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Extends the ProxyServerOptions with some additional properties
|
|
91
|
+
* for configuring the HTTPS proxy server.
|
|
92
|
+
*/
|
|
6
93
|
interface BaseHttpsProxyConfig extends ProxyServerOptions {
|
|
7
94
|
protocol?: string;
|
|
8
95
|
/** defaults to 'localhost' */
|
|
9
96
|
hostname?: string;
|
|
10
97
|
/** defaults to 8080 */
|
|
11
98
|
port?: number;
|
|
12
|
-
target?: string;
|
|
13
|
-
forward?: string;
|
|
14
99
|
}
|
|
15
100
|
|
|
16
101
|
declare module '@gasket/core' {
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-https-proxy",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.2",
|
|
4
4
|
"description": "Adds support for running an https proxy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib",
|
|
9
|
-
"cjs"
|
|
9
|
+
"cjs",
|
|
10
|
+
"EXAMPLES.md"
|
|
10
11
|
],
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
@@ -36,12 +37,12 @@
|
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"vitest": "^3.2.0",
|
|
39
|
-
"@gasket/cjs": "^7.0.
|
|
40
|
-
"@gasket/
|
|
41
|
-
"@gasket/
|
|
42
|
-
"@gasket/plugin-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
40
|
+
"@gasket/cjs": "^7.0.2",
|
|
41
|
+
"@gasket/core": "^7.6.3",
|
|
42
|
+
"@gasket/plugin-https": "^7.3.12",
|
|
43
|
+
"@gasket/plugin-logger": "^7.3.8",
|
|
44
|
+
"@gasket/plugin-metadata": "^7.5.4",
|
|
45
|
+
"create-gasket-app": "^7.4.13"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|
|
47
48
|
"build": "gasket-cjs ./lib",
|