@gasket/plugin-https-proxy 7.4.1 → 7.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/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/cjs/create.cjs CHANGED
@@ -7,10 +7,13 @@ Object.defineProperty(exports, /** @type {import('@gasket/core').HookHandler<'cr
7
7
  return create;
8
8
  }
9
9
  });
10
- const _module = require("module");
11
- const require1 = (0, _module.createRequire)(require("url").pathToFileURL(__filename).toString());
12
- const pkgJson = require1('../package.json');
13
- const { name, version } = pkgJson;
10
+ const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
11
+ function _interop_require_default(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ const { name, version } = _packagejson.default;
14
17
  function create(gasket, { pkg, gasketConfig }) {
15
18
  gasketConfig.addPlugin('pluginHttpsProxy', name);
16
19
  pkg.add('dependencies', {
package/cjs/index.cjs CHANGED
@@ -11,15 +11,13 @@ Object.defineProperty(exports, /** @type {import('@gasket/core').Plugin} */ "def
11
11
  });
12
12
  const _create = /*#__PURE__*/ _interop_require_default(require("./create.cjs"));
13
13
  const _actions = require("./actions.cjs");
14
- const _module = require("module");
14
+ const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
15
15
  function _interop_require_default(obj) {
16
16
  return obj && obj.__esModule ? obj : {
17
17
  default: obj
18
18
  };
19
19
  }
20
- const require1 = (0, _module.createRequire)(require("url").pathToFileURL(__filename).toString());
21
- const pkgJson = require1('../package.json');
22
- const { name, version, description } = pkgJson;
20
+ const { name, version, description } = _packagejson.default;
23
21
  const _default = {
24
22
  name,
25
23
  version,
package/lib/create.js CHANGED
@@ -1,7 +1,5 @@
1
- import { createRequire } from 'module';
2
- const require = createRequire(import.meta.url);
3
- const pkgJson = require('../package.json');
4
- const { name, version } = pkgJson;
1
+ import packageJson from '../package.json' with { type: 'json' };
2
+ const { name, version } = packageJson;
5
3
 
6
4
  /** @type {import('@gasket/core').HookHandler<'create'>} */
7
5
  export default function create(gasket, { pkg, gasketConfig }) {
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/lib/index.js CHANGED
@@ -3,10 +3,8 @@
3
3
 
4
4
  import create from './create.js';
5
5
  import { actions } from './actions.js';
6
- import { createRequire } from 'module';
7
- const require = createRequire(import.meta.url);
8
- const pkgJson = require('../package.json');
9
- const { name, version, description } = pkgJson;
6
+ import packageJson from '../package.json' with { type: 'json' };
7
+ const { name, version, description } = packageJson;
10
8
 
11
9
  /** @type {import('@gasket/core').Plugin} */
12
10
  export default {
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@gasket/plugin-https-proxy",
3
- "version": "7.4.1",
3
+ "version": "7.5.0",
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.1",
40
- "@gasket/plugin-https": "^7.3.10",
41
- "@gasket/core": "^7.6.1",
42
- "@gasket/plugin-metadata": "^7.5.2",
43
- "create-gasket-app": "^7.4.11",
44
- "@gasket/plugin-logger": "^7.3.6"
40
+ "@gasket/cjs": "^7.1.0",
41
+ "@gasket/core": "^7.6.3",
42
+ "@gasket/plugin-https": "^7.4.0",
43
+ "@gasket/plugin-logger": "^7.4.0",
44
+ "@gasket/plugin-metadata": "^7.5.5",
45
+ "create-gasket-app": "^7.4.15"
45
46
  },
46
47
  "scripts": {
47
48
  "build": "gasket-cjs ./lib",