@lovrozagar/honey 0.5.3 → 0.6.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/README.md +1 -1
- package/dist/proxy.d.ts +3 -3
- package/dist/proxy.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/proxy.ts +6 -5
package/README.md
CHANGED
|
@@ -955,7 +955,7 @@ app.all("/upstream/*path").proxy({
|
|
|
955
955
|
rewriteUrl: (url) => url.replace(/^\/upstream/, ""),
|
|
956
956
|
requestHeaders: { "x-forwarded-by": "honey" },
|
|
957
957
|
// or requestHeaders: (ctx, headers) => { headers.set("x-user", ctx.user.id) }
|
|
958
|
-
timeout: 10_000, // or (ctx) => 5_000;
|
|
958
|
+
timeout: 10_000, // or (ctx) => 5_000; omit for no abort; disabled for WS upgrades
|
|
959
959
|
onResponse: (ctx, response) => {
|
|
960
960
|
response.headers.set("x-proxied", "1")
|
|
961
961
|
},
|
package/dist/proxy.d.ts
CHANGED
|
@@ -33,9 +33,9 @@ export type ProxyConfig<TCtx> = {
|
|
|
33
33
|
*/
|
|
34
34
|
rewriteUrl?: (url: string, ctx: TCtx) => string;
|
|
35
35
|
/**
|
|
36
|
-
* Timeout in milliseconds.
|
|
37
|
-
* Accepts a number or a function that receives ctx
|
|
38
|
-
* Disabled for WebSocket upgrades.
|
|
36
|
+
* Timeout in milliseconds. Omitted: no abort. `0` or a non-positive
|
|
37
|
+
* value: no abort. Accepts a number or a function that receives ctx
|
|
38
|
+
* and returns a number. Disabled for WebSocket upgrades.
|
|
39
39
|
*/
|
|
40
40
|
timeout?: number | ((ctx: TCtx) => number);
|
|
41
41
|
};
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,IAAI;IAC/B;;;;;;;O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,KAAK,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAA;IAE1F;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC,CAAA;IAEjF;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,KAAK,MAAM,CAAA;IAE/C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,CAAC,CAAA;CAC1C,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,CA8FpG"}
|
package/package.json
CHANGED
package/src/proxy.ts
CHANGED
|
@@ -42,9 +42,9 @@ export type ProxyConfig<TCtx> = {
|
|
|
42
42
|
rewriteUrl?: (url: string, ctx: TCtx) => string
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Timeout in milliseconds.
|
|
46
|
-
* Accepts a number or a function that receives ctx
|
|
47
|
-
* Disabled for WebSocket upgrades.
|
|
45
|
+
* Timeout in milliseconds. Omitted: no abort. `0` or a non-positive
|
|
46
|
+
* value: no abort. Accepts a number or a function that receives ctx
|
|
47
|
+
* and returns a number. Disabled for WebSocket upgrades.
|
|
48
48
|
*/
|
|
49
49
|
timeout?: number | ((ctx: TCtx) => number)
|
|
50
50
|
}
|
|
@@ -58,7 +58,7 @@ export type ProxyConfig<TCtx> = {
|
|
|
58
58
|
* which has both fields — we access them via property access on the object.
|
|
59
59
|
*/
|
|
60
60
|
export function createProxyHandler<TCtx>(config: ProxyConfig<TCtx>): (ctx: TCtx) => Promise<Response> {
|
|
61
|
-
const timeoutOpt = config.timeout
|
|
61
|
+
const timeoutOpt = config.timeout
|
|
62
62
|
|
|
63
63
|
return async (ctx: TCtx) => {
|
|
64
64
|
const timeoutMs = typeof timeoutOpt === "function" ? timeoutOpt(ctx) : timeoutOpt
|
|
@@ -67,6 +67,7 @@ export function createProxyHandler<TCtx>(config: ProxyConfig<TCtx>): (ctx: TCtx)
|
|
|
67
67
|
const request = c["req"] as Request
|
|
68
68
|
const method = request.method
|
|
69
69
|
const isWs = request.headers.get("upgrade") === "websocket"
|
|
70
|
+
const abortMs = !isWs && timeoutMs != null && timeoutMs > 0 ? timeoutMs : undefined
|
|
70
71
|
|
|
71
72
|
/* URL resolution — path + query, no new URL() */
|
|
72
73
|
const rawUrl = request.url
|
|
@@ -108,7 +109,7 @@ export function createProxyHandler<TCtx>(config: ProxyConfig<TCtx>): (ctx: TCtx)
|
|
|
108
109
|
headers,
|
|
109
110
|
method,
|
|
110
111
|
redirect: "manual",
|
|
111
|
-
signal:
|
|
112
|
+
signal: abortMs == null ? undefined : AbortSignal.timeout(abortMs),
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
/* duplex required for streaming body (Node needs it, CF handles implicitly) */
|