@gasket/plugin-https-proxy 7.6.0 → 7.6.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/cjs/actions.cjs +14 -3
- package/lib/actions.js +13 -3
- package/package.json +2 -2
package/cjs/actions.cjs
CHANGED
|
@@ -73,6 +73,17 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
73
73
|
search: path.slice(queryAt)
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Summarize a request failure for the log. Error properties and messages can hold request data,
|
|
78
|
+
* such as the full URL in the `input` of an invalid-URL error.
|
|
79
|
+
* @param {any} err - Error from proxying a request
|
|
80
|
+
* @returns {{ name?: string, code?: string }} Error name and code
|
|
81
|
+
*/ function requestFailure(err) {
|
|
82
|
+
return {
|
|
83
|
+
name: err?.name,
|
|
84
|
+
code: err?.code
|
|
85
|
+
};
|
|
86
|
+
}
|
|
76
87
|
/**
|
|
77
88
|
* Serve the proxy on a node http(s) server.
|
|
78
89
|
* http-proxy-3 would serve HTTP/2 over TLS, and its passes can throw synchronously on a
|
|
@@ -90,7 +101,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
90
101
|
try {
|
|
91
102
|
proxy.web(req, res);
|
|
92
103
|
} catch (err) {
|
|
93
|
-
logger.error('Request failed to proxy:', err);
|
|
104
|
+
logger.error('Request failed to proxy:', requestFailure(err));
|
|
94
105
|
if (res.headersSent) return void res.destroy();
|
|
95
106
|
res.writeHead(400, {
|
|
96
107
|
'content-type': 'text/plain'
|
|
@@ -104,7 +115,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
104
115
|
try {
|
|
105
116
|
proxy.ws(req, socket, head);
|
|
106
117
|
} catch (err) {
|
|
107
|
-
logger.error('Request failed to proxy:', err);
|
|
118
|
+
logger.error('Request failed to proxy:', requestFailure(err));
|
|
108
119
|
socket.destroy();
|
|
109
120
|
}
|
|
110
121
|
});
|
|
@@ -131,7 +142,7 @@ async function startProxyServer(gasket) {
|
|
|
131
142
|
if (proxyOpts.target) proxyOpts.target = withPathname(proxyOpts.target);
|
|
132
143
|
if (proxyOpts.forward) proxyOpts.forward = withPathname(proxyOpts.forward);
|
|
133
144
|
const proxy = (0, _httpproxy3.createServer)(proxyOpts).on('error', (err, req, res)=>{
|
|
134
|
-
logger.error('Request failed to proxy:', err);
|
|
145
|
+
logger.error('Request failed to proxy:', requestFailure(err));
|
|
135
146
|
// Answer the client so a failing target does not leave its connection open.
|
|
136
147
|
if (res instanceof _nodehttp.ServerResponse && !res.headersSent) {
|
|
137
148
|
res.writeHead(502, {
|
package/lib/actions.js
CHANGED
|
@@ -16,6 +16,16 @@ function withPathname(target) {
|
|
|
16
16
|
return { ...rest, pathname: path.slice(0, queryAt), search: path.slice(queryAt) };
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Summarize a request failure for the log. Error properties and messages can hold request data,
|
|
21
|
+
* such as the full URL in the `input` of an invalid-URL error.
|
|
22
|
+
* @param {any} err - Error from proxying a request
|
|
23
|
+
* @returns {{ name?: string, code?: string }} Error name and code
|
|
24
|
+
*/
|
|
25
|
+
function requestFailure(err) {
|
|
26
|
+
return { name: err?.name, code: err?.code };
|
|
27
|
+
}
|
|
28
|
+
|
|
19
29
|
/**
|
|
20
30
|
* Serve the proxy on a node http(s) server.
|
|
21
31
|
* http-proxy-3 would serve HTTP/2 over TLS, and its passes can throw synchronously on a
|
|
@@ -36,7 +46,7 @@ function listen(proxy, { ssl, ws, port, logger }) {
|
|
|
36
46
|
try {
|
|
37
47
|
proxy.web(req, res);
|
|
38
48
|
} catch (err) {
|
|
39
|
-
logger.error('Request failed to proxy:', err);
|
|
49
|
+
logger.error('Request failed to proxy:', requestFailure(err));
|
|
40
50
|
if (res.headersSent) return void res.destroy();
|
|
41
51
|
res.writeHead(400, { 'content-type': 'text/plain' });
|
|
42
52
|
res.end('Bad Request');
|
|
@@ -48,7 +58,7 @@ function listen(proxy, { ssl, ws, port, logger }) {
|
|
|
48
58
|
try {
|
|
49
59
|
proxy.ws(req, socket, head);
|
|
50
60
|
} catch (err) {
|
|
51
|
-
logger.error('Request failed to proxy:', err);
|
|
61
|
+
logger.error('Request failed to proxy:', requestFailure(err));
|
|
52
62
|
socket.destroy();
|
|
53
63
|
}
|
|
54
64
|
});
|
|
@@ -80,7 +90,7 @@ export async function startProxyServer(gasket) {
|
|
|
80
90
|
if (proxyOpts.forward) proxyOpts.forward = withPathname(proxyOpts.forward);
|
|
81
91
|
|
|
82
92
|
const proxy = createServer(proxyOpts).on('error', (err, req, res) => {
|
|
83
|
-
logger.error('Request failed to proxy:', err);
|
|
93
|
+
logger.error('Request failed to proxy:', requestFailure(err));
|
|
84
94
|
// Answer the client so a failing target does not leave its connection open.
|
|
85
95
|
if (res instanceof ServerResponse && !res.headersSent) {
|
|
86
96
|
res.writeHead(502, { 'content-type': 'text/plain' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gasket/plugin-https-proxy",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.1",
|
|
4
4
|
"description": "Adds support for running an https proxy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"vitest": "^3.2.0",
|
|
41
41
|
"@gasket/cjs": "^7.1.3",
|
|
42
42
|
"@gasket/core": "^7.7.7",
|
|
43
|
-
"@gasket/plugin-https": "^7.5.
|
|
43
|
+
"@gasket/plugin-https": "^7.5.1",
|
|
44
44
|
"@gasket/plugin-logger": "^7.5.1",
|
|
45
45
|
"@gasket/plugin-metadata": "^7.5.14",
|
|
46
46
|
"create-gasket-app": "^7.4.29"
|