@gasket/plugin-https-proxy 7.1.0-canary.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/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,99 @@
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
+ ## Actions
60
+
61
+ ### startProxyServer
62
+
63
+ Use this action to start the HTTPS proxy server.
64
+
65
+ ```js
66
+ import gasket from './gasket.js';
67
+ gasket.actions.startProxyServer();
68
+ ```
69
+
70
+ ## Lifecycles
71
+
72
+ ### httpsProxy
73
+
74
+ While most settings can be configured in the `httpsProxy` configuration,
75
+ this lifecycle can be used to adjust the `httpsProxy` options when
76
+ the HTTPS proxy server is being started, which is helpful for dynamic
77
+ configuration and loading of certs.
78
+
79
+ ```js
80
+ export default {
81
+ name: 'example-plugin',
82
+ hooks: {
83
+ httpsProxy: async function (gasket, httpsProxyConfig) {
84
+ return {
85
+ ...devProxyConfig,
86
+ hostname: 'local.example.com',
87
+ port: 8443
88
+ }
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ## License
95
+
96
+ [MIT](./LICENSE.md)
97
+
98
+ [http-proxy]: https://www.npmjs.com/package/http-proxy
99
+ [options]: https://www.npmjs.com/package/http-proxy#options
package/lib/actions.js ADDED
@@ -0,0 +1,27 @@
1
+ /// <reference types="./index.d.ts"/>
2
+
3
+ import proxy from 'http-proxy';
4
+
5
+ /** @type {import('@gasket/core').ActionHandler<'startProxyServer'>} */
6
+ export async function startProxyServer(gasket) {
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,11 @@
1
+ import { createRequire } from 'module';
2
+ const require = createRequire(import.meta.url);
3
+ const { name, version } = require('../package.json');
4
+
5
+ /** @type {import('@gasket/core').HookHandler<'create'>} */
6
+ export default function create(gasket, { pkg, gasketConfig }) {
7
+ gasketConfig.addPlugin('pluginHttpsProxy', name);
8
+ pkg.add('dependencies', {
9
+ [name]: `^${version}`
10
+ });
11
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { Plugin } from '@gasket/core';
2
+ import type { ServerOptions as ProxyServerOptions, Server as ProxyServer } from 'http-proxy';
3
+ import http from 'http';
4
+
5
+ interface BaseHttpsProxyConfig extends ProxyServerOptions {
6
+ protocol?: string;
7
+ /** defaults to 'localhost' */
8
+ hostname?: string;
9
+ /** defaults to 8080 */
10
+ port?: number;
11
+ }
12
+
13
+ declare module '@gasket/core' {
14
+ export type HttpsProxyConfig = RequireAtLeastOne<BaseHttpsProxyConfig, 'target' | 'forward'>;
15
+
16
+ export interface GasketConfig {
17
+ httpsProxy?: HttpsProxyConfig
18
+ }
19
+
20
+ export interface HookExecTypes {
21
+ httpsProxy(proxyConfig: HttpsProxyConfig): MaybeAsync<HttpsProxyConfig>,
22
+ }
23
+
24
+ export interface GasketActions {
25
+ startProxyServer: () => Promise<ProxyServer>;
26
+ }
27
+ }
28
+
29
+ const plugin: Plugin = {
30
+ name: '@gasket/plugin-plugin-https-proxy',
31
+ hooks: {}
32
+ };
33
+
34
+ export default plugin;
package/lib/index.js ADDED
@@ -0,0 +1,47 @@
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 { name, version, description } = require('../package.json');
9
+
10
+ /** @type {import('@gasket/core').Plugin} */
11
+ export default {
12
+ name,
13
+ version,
14
+ description,
15
+ actions,
16
+ hooks: {
17
+ create,
18
+ metadata(gasket, meta) {
19
+ return {
20
+ ...meta,
21
+ actions: [
22
+ {
23
+ name: 'startProxyServer',
24
+ description: 'Start the proxy server',
25
+ link: 'README.md#startProxyServer'
26
+ }
27
+ ],
28
+ lifecycles: [
29
+ {
30
+ name: 'httpsProxy',
31
+ method: 'execWaterfall',
32
+ description: 'Setup the httpsProxy options',
33
+ link: 'README.md#httpsProxy'
34
+ }
35
+ ],
36
+ configurations: [
37
+ {
38
+ name: 'httpsProxy',
39
+ link: 'README.md#configuration',
40
+ description: 'http-proxy config object',
41
+ type: 'object'
42
+ }
43
+ ]
44
+ };
45
+ }
46
+ }
47
+ };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@gasket/plugin-https-proxy",
3
+ "version": "7.1.0-canary.1",
4
+ "description": "Adds support for running an https proxy",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib"
9
+ ],
10
+ "type": "module",
11
+ "scripts": {
12
+ "lint": "eslint .",
13
+ "lint:fix": "npm run lint -- --fix",
14
+ "test": "vitest --watch=false",
15
+ "test:watch": "vitest",
16
+ "test:coverage": "npm run test -- --coverage",
17
+ "posttest": "npm run lint && npm run typecheck",
18
+ "typecheck": "tsc",
19
+ "typecheck:watch": "tsc --watch"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+ssh://git@github.com/godaddy/gasket.git"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "keywords": [
29
+ "https",
30
+ "proxy",
31
+ "gasket",
32
+ "plugin"
33
+ ],
34
+ "author": "GoDaddy Operating Company, LLC",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/godaddy/gasket/issues"
38
+ },
39
+ "homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-https-proxy",
40
+ "dependencies": {
41
+ "http-proxy": "^1.18.1"
42
+ },
43
+ "devDependencies": {
44
+ "@gasket/core": "7.1.0-canary.1",
45
+ "@gasket/plugin-logger": "7.1.0-canary.1",
46
+ "@types/node": "^20.12.5",
47
+ "eslint": "^8.56.0",
48
+ "eslint-config-godaddy": "^7.1.1",
49
+ "eslint-plugin-jest": "^28.6.0",
50
+ "eslint-plugin-json": "^3.1.0",
51
+ "eslint-plugin-unicorn": "^55.0.0",
52
+ "typescript": "^5.4.5",
53
+ "vitest": "^2.1.5"
54
+ },
55
+ "eslintConfig": {
56
+ "extends": [
57
+ "godaddy",
58
+ "plugin:jest/recommended"
59
+ ],
60
+ "plugins": [
61
+ "unicorn"
62
+ ],
63
+ "rules": {
64
+ "unicorn/filename-case": "error"
65
+ }
66
+ },
67
+ "gitHead": "79706568a4b2a7aa2621bf1f0bdaded08c396ed4"
68
+ }