@gasket/plugin-https-proxy 0.0.0-canary-20250922152503
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/LICENSE.md +21 -0
- package/README.md +174 -0
- package/cjs/actions.cjs +39 -0
- package/cjs/create.cjs +19 -0
- package/cjs/index.cjs +64 -0
- package/cjs/package.json +1 -0
- package/lib/actions.js +27 -0
- package/lib/create.js +12 -0
- package/lib/index.d.ts +119 -0
- package/lib/index.js +53 -0
- package/package.json +59 -0
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/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 GoDaddy Operating Company, LLC.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# @gasket/plugin-https-proxy
|
|
2
|
+
|
|
3
|
+
Create an HTTPS proxy server with Gasket to use as a sidecar for frameworks that
|
|
4
|
+
do not handle HTTPS, such as Next.js. This can be useful for local development
|
|
5
|
+
when you want to test HTTPS features and use secure cookies for
|
|
6
|
+
authentication, etc.
|
|
7
|
+
It can also be used in production if it is necessary for your application to
|
|
8
|
+
handle HTTPS requests on the container.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
npm i @gasket/plugin-https-proxy
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Update your `gasket` file plugin configuration:
|
|
17
|
+
|
|
18
|
+
```diff
|
|
19
|
+
// gasket.js
|
|
20
|
+
|
|
21
|
+
+ import pluginHttpsProxy from '@gasket/plugin-https-proxy';
|
|
22
|
+
|
|
23
|
+
export default makeGasket({
|
|
24
|
+
plugins: [
|
|
25
|
+
+ pluginHttpsProxy
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
To be set under `httpsProxy` in the `gasket.js` file.
|
|
33
|
+
|
|
34
|
+
This uses the [http-proxy] package and its complete set of available [options].
|
|
35
|
+
|
|
36
|
+
```diff
|
|
37
|
+
// gasket.js
|
|
38
|
+
export default makeGasket({
|
|
39
|
+
+ httpsProxy: {
|
|
40
|
+
+ protocol: 'https',
|
|
41
|
+
+ hostname: 'my-host.com',
|
|
42
|
+
+ port: 443,
|
|
43
|
+
+ xfwd: true,
|
|
44
|
+
+ ws: true,
|
|
45
|
+
+ target: {
|
|
46
|
+
+ host: 'localhost',
|
|
47
|
+
+ port: 80
|
|
48
|
+
+ }
|
|
49
|
+
+ }
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The above example forwards HTTPS requests on port `443` to `localhost:80`.
|
|
54
|
+
|
|
55
|
+
The `protocol` and `hostname` are only used for logging about the proxy server
|
|
56
|
+
and should not be confused with `target.protocol` and `target.host` which
|
|
57
|
+
are used for the actual destination server.
|
|
58
|
+
|
|
59
|
+
### Example SNI Config
|
|
60
|
+
|
|
61
|
+
While not specifically called out in the [http-proxy] documentation, the
|
|
62
|
+
`ssl` settings are what get passed to node's `createServer` method.
|
|
63
|
+
As such, you can use `SNICallback` from the [createServer options].
|
|
64
|
+
|
|
65
|
+
```diff
|
|
66
|
+
// gasket.js
|
|
67
|
+
export default makeGasket({
|
|
68
|
+
httpsProxy: {
|
|
69
|
+
protocol: 'https',
|
|
70
|
+
hostname: 'my-host.com',
|
|
71
|
+
port: 443,
|
|
72
|
+
xfwd: true,
|
|
73
|
+
ws: true,
|
|
74
|
+
target: {
|
|
75
|
+
host: 'localhost',
|
|
76
|
+
port: 80
|
|
77
|
+
},
|
|
78
|
+
+ ssl: {
|
|
79
|
+
+ SNICallback: (hostname, cb) => {
|
|
80
|
+
+ const ctx = tls.createSecureContext({
|
|
81
|
+
+ key: fs.readFileSync(`./certs/${hostname}.key`),
|
|
82
|
+
+ cert: fs.readFileSync(`./certs/${hostname}.crt`)
|
|
83
|
+
+ });
|
|
84
|
+
+ cb(null, ctx);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
> The above snippet is for demonstration purposes only.
|
|
92
|
+
> You should not be reading your certs from the filesystem for each request.
|
|
93
|
+
|
|
94
|
+
## Actions
|
|
95
|
+
|
|
96
|
+
### startProxyServer
|
|
97
|
+
|
|
98
|
+
Use this action to start the HTTPS proxy server.
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
import gasket from './gasket.js';
|
|
102
|
+
gasket.actions.startProxyServer();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
The complete flow is:
|
|
107
|
+
|
|
108
|
+
1. Waits for `gasket.isReady` (ensuring async configuration is complete)
|
|
109
|
+
2. Executes the `prebootHttpsProxy` lifecycle (one-time initialization)
|
|
110
|
+
3. Executes the `httpsProxy` lifecycle for dynamic configuration
|
|
111
|
+
4. Creates and starts the proxy server
|
|
112
|
+
## Lifecycles
|
|
113
|
+
|
|
114
|
+
### prebootHttpsProxy
|
|
115
|
+
|
|
116
|
+
This lifecycle is executed before the proxy server is started. It is a good place to
|
|
117
|
+
execute operations that need to happen before the proxy server is started.
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
/**
|
|
121
|
+
* Executed before the proxy server is started.
|
|
122
|
+
*
|
|
123
|
+
* @param {Gasket} gasket Gasket API.
|
|
124
|
+
*/
|
|
125
|
+
prebootHttpsProxy: async function prebootHttpsProxy(gasket) {
|
|
126
|
+
// async operations
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### When to use `prebootHttpsProxy` vs `prepare`
|
|
131
|
+
|
|
132
|
+
The `preboot` lifecycle runs **once** when the proxy server starts, while the `prepare` lifecycle runs for **every** Gasket instance creation. Use `preboot` for:
|
|
133
|
+
|
|
134
|
+
- One-time proxy server initialization
|
|
135
|
+
- Setting up shared SSL/TLS contexts
|
|
136
|
+
- Loading certificates that will be reused across requests
|
|
137
|
+
- Establishing persistent connections or pools
|
|
138
|
+
|
|
139
|
+
Use `prepare` for:
|
|
140
|
+
|
|
141
|
+
- Per-instance configuration
|
|
142
|
+
- Setting up instance-specific state
|
|
143
|
+
- Operations that need fresh initialization for each Gasket instance
|
|
144
|
+
|
|
145
|
+
> **Note**: In SSR applications, new Gasket instances may be created for different contexts, causing `prepare` to run multiple times. For proxy servers, this can lead to unnecessary overhead. Use `preboot` for expensive initialization operations.
|
|
146
|
+
### httpsProxy
|
|
147
|
+
|
|
148
|
+
While most settings can be configured in the `httpsProxy` configuration,
|
|
149
|
+
this lifecycle can be used to adjust the `httpsProxy` options when
|
|
150
|
+
the HTTPS proxy server is being started, which is helpful for dynamic
|
|
151
|
+
configuration and loading of certs.
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
export default {
|
|
155
|
+
name: 'example-plugin',
|
|
156
|
+
hooks: {
|
|
157
|
+
httpsProxy: async function (gasket, httpsProxyConfig) {
|
|
158
|
+
return {
|
|
159
|
+
...httpsProxyConfig,
|
|
160
|
+
hostname: 'local.example.com',
|
|
161
|
+
port: 8443
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
[MIT](./LICENSE.md)
|
|
171
|
+
|
|
172
|
+
[http-proxy]: https://www.npmjs.com/package/http-proxy
|
|
173
|
+
[options]: https://www.npmjs.com/package/http-proxy#options
|
|
174
|
+
[createServer options]: https://nodejs.org/docs/latest-v22.x/api/tls.html#tlscreateserveroptions-secureconnectionlistener
|
package/cjs/actions.cjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
function _export(target, all) {
|
|
5
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: all[name]
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
_export(exports, {
|
|
11
|
+
actions: function() {
|
|
12
|
+
return actions;
|
|
13
|
+
},
|
|
14
|
+
startProxyServer: function() {
|
|
15
|
+
return startProxyServer;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const _httpproxy = /*#__PURE__*/ _interop_require_default(require("http-proxy"));
|
|
19
|
+
function _interop_require_default(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function startProxyServer(gasket) {
|
|
25
|
+
await gasket.isReady;
|
|
26
|
+
await gasket.exec('prebootHttpsProxy');
|
|
27
|
+
const { httpsProxy } = gasket.config;
|
|
28
|
+
const { logger } = gasket;
|
|
29
|
+
const opts = await gasket.execWaterfall('httpsProxy', httpsProxy);
|
|
30
|
+
const { protocol = 'http', hostname = 'localhost', port = 8080, ...proxyOpts } = opts;
|
|
31
|
+
const server = _httpproxy.default.createServer(proxyOpts).on('error', (err)=>{
|
|
32
|
+
logger.error('Request failed to proxy:', err);
|
|
33
|
+
}).listen(port);
|
|
34
|
+
logger.info(`Proxy server started: ${protocol}://${hostname}:${port}`);
|
|
35
|
+
return server;
|
|
36
|
+
}
|
|
37
|
+
const actions = {
|
|
38
|
+
startProxyServer
|
|
39
|
+
};
|
package/cjs/create.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
Object.defineProperty(exports, /** @type {import('@gasket/core').HookHandler<'create'>} */ "default", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function() {
|
|
7
|
+
return create;
|
|
8
|
+
}
|
|
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;
|
|
14
|
+
function create(gasket, { pkg, gasketConfig }) {
|
|
15
|
+
gasketConfig.addPlugin('pluginHttpsProxy', name);
|
|
16
|
+
pkg.add('dependencies', {
|
|
17
|
+
[name]: `^${version}`
|
|
18
|
+
});
|
|
19
|
+
}
|
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="create-gasket-app" />
|
|
2
|
+
/// <reference types="@gasket/plugin-metadata" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, /** @type {import('@gasket/core').Plugin} */ "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return _default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const _create = /*#__PURE__*/ _interop_require_default(require("./create.cjs"));
|
|
13
|
+
const _actions = require("./actions.cjs");
|
|
14
|
+
const _module = require("module");
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const require1 = (0, _module.createRequire)(require("url").pathToFileURL(__filename).toString());
|
|
21
|
+
const pkgJson = require1('../package.json');
|
|
22
|
+
const { name, version, description } = pkgJson;
|
|
23
|
+
const _default = {
|
|
24
|
+
name,
|
|
25
|
+
version,
|
|
26
|
+
description,
|
|
27
|
+
actions: _actions.actions,
|
|
28
|
+
hooks: {
|
|
29
|
+
create: _create.default,
|
|
30
|
+
metadata (gasket, meta) {
|
|
31
|
+
return {
|
|
32
|
+
...meta,
|
|
33
|
+
actions: [
|
|
34
|
+
{
|
|
35
|
+
name: 'startProxyServer',
|
|
36
|
+
description: 'Start the proxy server',
|
|
37
|
+
link: 'README.md#startProxyServer'
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
lifecycles: [
|
|
41
|
+
{
|
|
42
|
+
name: 'prebootHttpsProxy',
|
|
43
|
+
description: 'Executed before the proxy server is started.',
|
|
44
|
+
link: 'README.md#prebootHttpsProxy'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'httpsProxy',
|
|
48
|
+
method: 'execWaterfall',
|
|
49
|
+
description: 'Setup the httpsProxy options',
|
|
50
|
+
link: 'README.md#httpsProxy'
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
configurations: [
|
|
54
|
+
{
|
|
55
|
+
name: 'httpsProxy',
|
|
56
|
+
link: 'README.md#configuration',
|
|
57
|
+
description: 'http-proxy config object',
|
|
58
|
+
type: 'object'
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/lib/actions.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import proxy from 'http-proxy';
|
|
2
|
+
|
|
3
|
+
/** @type {import('@gasket/core').ActionHandler<'startProxyServer'>} */
|
|
4
|
+
export async function startProxyServer(gasket) {
|
|
5
|
+
await gasket.isReady;
|
|
6
|
+
await gasket.exec('prebootHttpsProxy');
|
|
7
|
+
const { httpsProxy } = gasket.config;
|
|
8
|
+
const { logger } = gasket;
|
|
9
|
+
|
|
10
|
+
const opts = await gasket.execWaterfall('httpsProxy', httpsProxy);
|
|
11
|
+
|
|
12
|
+
const { protocol = 'http', hostname = 'localhost', port = 8080, ...proxyOpts } = opts;
|
|
13
|
+
const server = proxy.createServer(
|
|
14
|
+
proxyOpts
|
|
15
|
+
).on('error', (err) => {
|
|
16
|
+
logger.error('Request failed to proxy:', err);
|
|
17
|
+
}).listen(
|
|
18
|
+
port
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
logger.info(`Proxy server started: ${protocol}://${hostname}:${port}`);
|
|
22
|
+
return server;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const actions = {
|
|
26
|
+
startProxyServer
|
|
27
|
+
};
|
package/lib/create.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const pkgJson = require('../package.json');
|
|
4
|
+
const { name, version } = pkgJson;
|
|
5
|
+
|
|
6
|
+
/** @type {import('@gasket/core').HookHandler<'create'>} */
|
|
7
|
+
export default function create(gasket, { pkg, gasketConfig }) {
|
|
8
|
+
gasketConfig.addPlugin('pluginHttpsProxy', name);
|
|
9
|
+
pkg.add('dependencies', {
|
|
10
|
+
[name]: `^${version}`
|
|
11
|
+
});
|
|
12
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { Plugin, MaybeAsync } from '@gasket/core';
|
|
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
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Extends the ProxyServerOptions with some additional properties
|
|
91
|
+
* for configuring the HTTPS proxy server.
|
|
92
|
+
*/
|
|
93
|
+
interface BaseHttpsProxyConfig extends ProxyServerOptions {
|
|
94
|
+
protocol?: string;
|
|
95
|
+
/** defaults to 'localhost' */
|
|
96
|
+
hostname?: string;
|
|
97
|
+
/** defaults to 8080 */
|
|
98
|
+
port?: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare module '@gasket/core' {
|
|
102
|
+
export type HttpsProxyConfig = RequireAtLeastOne<BaseHttpsProxyConfig, 'target' | 'forward'>;
|
|
103
|
+
|
|
104
|
+
export interface GasketConfig {
|
|
105
|
+
httpsProxy?: HttpsProxyConfig
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface HookExecTypes {
|
|
109
|
+
prebootHttpsProxy(): MaybeAsync<void>;
|
|
110
|
+
httpsProxy(proxyConfig: HttpsProxyConfig): MaybeAsync<HttpsProxyConfig>,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface GasketActions {
|
|
114
|
+
startProxyServer: () => Promise<ProxyServer>;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
declare const plugin: Plugin;
|
|
119
|
+
export default plugin;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="create-gasket-app" />
|
|
2
|
+
/// <reference types="@gasket/plugin-metadata" />
|
|
3
|
+
|
|
4
|
+
import create from './create.js';
|
|
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;
|
|
10
|
+
|
|
11
|
+
/** @type {import('@gasket/core').Plugin} */
|
|
12
|
+
export default {
|
|
13
|
+
name,
|
|
14
|
+
version,
|
|
15
|
+
description,
|
|
16
|
+
actions,
|
|
17
|
+
hooks: {
|
|
18
|
+
create,
|
|
19
|
+
metadata(gasket, meta) {
|
|
20
|
+
return {
|
|
21
|
+
...meta,
|
|
22
|
+
actions: [
|
|
23
|
+
{
|
|
24
|
+
name: 'startProxyServer',
|
|
25
|
+
description: 'Start the proxy server',
|
|
26
|
+
link: 'README.md#startProxyServer'
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
lifecycles: [
|
|
30
|
+
{
|
|
31
|
+
name: 'prebootHttpsProxy',
|
|
32
|
+
description: 'Executed before the proxy server is started.',
|
|
33
|
+
link: 'README.md#prebootHttpsProxy'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'httpsProxy',
|
|
37
|
+
method: 'execWaterfall',
|
|
38
|
+
description: 'Setup the httpsProxy options',
|
|
39
|
+
link: 'README.md#httpsProxy'
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
configurations: [
|
|
43
|
+
{
|
|
44
|
+
name: 'httpsProxy',
|
|
45
|
+
link: 'README.md#configuration',
|
|
46
|
+
description: 'http-proxy config object',
|
|
47
|
+
type: 'object'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gasket/plugin-https-proxy",
|
|
3
|
+
"version": "0.0.0-canary-20250922152503",
|
|
4
|
+
"description": "Adds support for running an https proxy",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"cjs",
|
|
10
|
+
"EXAMPLES.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
|
+
"import": "./lib/index.js",
|
|
16
|
+
"require": "./cjs/index.cjs",
|
|
17
|
+
"default": "./cjs/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"repository": "godaddy/gasket.git",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"gasket",
|
|
27
|
+
"https",
|
|
28
|
+
"plugin",
|
|
29
|
+
"proxy"
|
|
30
|
+
],
|
|
31
|
+
"author": "GoDaddy Operating Company, LLC",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"bugs": "https://github.com/godaddy/gasket/issues",
|
|
34
|
+
"homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-https-proxy",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"http-proxy": "^1.18.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"vitest": "^3.2.0",
|
|
40
|
+
"@gasket/core": "^0.0.0-canary-20250922152503",
|
|
41
|
+
"@gasket/plugin-logger": "^0.0.0-canary-20250922152503",
|
|
42
|
+
"@gasket/cjs": "^0.0.0-canary-20250922152503",
|
|
43
|
+
"@gasket/plugin-https": "^0.0.0-canary-20250922152503",
|
|
44
|
+
"@gasket/plugin-metadata": "^0.0.0-canary-20250922152503",
|
|
45
|
+
"create-gasket-app": "^0.0.0-canary-20250922152503"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "gasket-cjs ./lib",
|
|
49
|
+
"build:watch": "pnpm run build --watch",
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"lint:fix": "pnpm run lint --fix",
|
|
52
|
+
"posttest": "pnpm run lint && pnpm run typecheck",
|
|
53
|
+
"test": "vitest --watch=false",
|
|
54
|
+
"test:coverage": "pnpm run test --coverage",
|
|
55
|
+
"test:watch": "vitest",
|
|
56
|
+
"typecheck": "tsc",
|
|
57
|
+
"typecheck:watch": "tsc --watch"
|
|
58
|
+
}
|
|
59
|
+
}
|