vite-plugin-rpx 0.11.21 → 0.11.22
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/dist/index.js +29 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -22765,6 +22765,7 @@ class UpstreamPool {
|
|
|
22765
22765
|
host;
|
|
22766
22766
|
port;
|
|
22767
22767
|
maxTotal;
|
|
22768
|
+
key;
|
|
22768
22769
|
idle = [];
|
|
22769
22770
|
waiters = [];
|
|
22770
22771
|
open = 0;
|
|
@@ -22773,10 +22774,11 @@ class UpstreamPool {
|
|
|
22773
22774
|
maxWaiters;
|
|
22774
22775
|
checkoutIdleMs = checkoutIdleMs();
|
|
22775
22776
|
inUse = new Set;
|
|
22776
|
-
constructor(host, port, maxTotal) {
|
|
22777
|
+
constructor(host, port, maxTotal, key = "") {
|
|
22777
22778
|
this.host = host;
|
|
22778
22779
|
this.port = port;
|
|
22779
22780
|
this.maxTotal = maxTotal;
|
|
22781
|
+
this.key = key;
|
|
22780
22782
|
this.maxWaiters = maxQueued(maxTotal);
|
|
22781
22783
|
}
|
|
22782
22784
|
trackCheckout(conn) {
|
|
@@ -22935,6 +22937,8 @@ class UpstreamPool {
|
|
|
22935
22937
|
if (this.idle.length === 0 && this.inUse.size === 0 && this.sweeper) {
|
|
22936
22938
|
clearInterval(this.sweeper);
|
|
22937
22939
|
this.sweeper = null;
|
|
22940
|
+
if (this.key && pools.get(this.key) === this)
|
|
22941
|
+
pools.delete(this.key);
|
|
22938
22942
|
}
|
|
22939
22943
|
}
|
|
22940
22944
|
}
|
|
@@ -22944,7 +22948,7 @@ function poolFor(hostPort, maxPerHost) {
|
|
|
22944
22948
|
const idx = hostPort.lastIndexOf(":");
|
|
22945
22949
|
const host = idx === -1 ? hostPort : hostPort.slice(0, idx);
|
|
22946
22950
|
const port = idx === -1 ? 80 : Number(hostPort.slice(idx + 1));
|
|
22947
|
-
pool = new UpstreamPool(host, port, maxPerHost);
|
|
22951
|
+
pool = new UpstreamPool(host, port, maxPerHost, hostPort);
|
|
22948
22952
|
pools.set(hostPort, pool);
|
|
22949
22953
|
}
|
|
22950
22954
|
return pool;
|
|
@@ -23519,6 +23523,9 @@ var init_static_files = __esm(() => {
|
|
|
23519
23523
|
});
|
|
23520
23524
|
|
|
23521
23525
|
// ../rpx/src/proxy-handler.ts
|
|
23526
|
+
function wsPendingCapBytes() {
|
|
23527
|
+
return Math.max(0, Number(process.env.RPX_MAX_WS_PENDING_BYTES)) || 8 * 1024 * 1024;
|
|
23528
|
+
}
|
|
23522
23529
|
function extractHostname2(req) {
|
|
23523
23530
|
const hostHeader = req.headers.get("host") || "";
|
|
23524
23531
|
const colon = hostHeader.indexOf(":");
|
|
@@ -23678,6 +23685,7 @@ function createProxyFetchHandler(getRoute, verbose, onNoRoute) {
|
|
|
23678
23685
|
}
|
|
23679
23686
|
function createProxyWebSocketHandler(verbose) {
|
|
23680
23687
|
const state = new WeakMap;
|
|
23688
|
+
const maxPendingBytes = wsPendingCapBytes();
|
|
23681
23689
|
return {
|
|
23682
23690
|
open(ws) {
|
|
23683
23691
|
const { targetUrl, forwardHeaders } = ws.data;
|
|
@@ -23690,13 +23698,14 @@ function createProxyWebSocketHandler(verbose) {
|
|
|
23690
23698
|
return;
|
|
23691
23699
|
}
|
|
23692
23700
|
upstream.binaryType = "arraybuffer";
|
|
23693
|
-
const st = { upstream, upstreamOpen: false, pending: [] };
|
|
23701
|
+
const st = { upstream, upstreamOpen: false, pending: [], pendingBytes: 0 };
|
|
23694
23702
|
state.set(ws, st);
|
|
23695
23703
|
upstream.addEventListener("open", () => {
|
|
23696
23704
|
st.upstreamOpen = true;
|
|
23697
23705
|
for (const frame of st.pending)
|
|
23698
23706
|
upstream.send(frame);
|
|
23699
23707
|
st.pending = [];
|
|
23708
|
+
st.pendingBytes = 0;
|
|
23700
23709
|
});
|
|
23701
23710
|
upstream.addEventListener("message", (ev) => {
|
|
23702
23711
|
ws.send(ev.data);
|
|
@@ -23718,10 +23727,24 @@ function createProxyWebSocketHandler(verbose) {
|
|
|
23718
23727
|
if (!st)
|
|
23719
23728
|
return;
|
|
23720
23729
|
const frame = typeof message === "string" ? message : new Uint8Array(message);
|
|
23721
|
-
if (st.upstreamOpen)
|
|
23730
|
+
if (st.upstreamOpen) {
|
|
23722
23731
|
st.upstream.send(frame);
|
|
23723
|
-
|
|
23724
|
-
|
|
23732
|
+
return;
|
|
23733
|
+
}
|
|
23734
|
+
const size = typeof frame === "string" ? Buffer.byteLength(frame) : frame.byteLength;
|
|
23735
|
+
if (st.pendingBytes + size > maxPendingBytes) {
|
|
23736
|
+
debugLog("ws", `pending buffer would exceed ${maxPendingBytes}B before upstream open; closing socket`, verbose);
|
|
23737
|
+
try {
|
|
23738
|
+
ws.close(1009, "buffer limit");
|
|
23739
|
+
} catch {}
|
|
23740
|
+
try {
|
|
23741
|
+
st.upstream.close(1011, "client buffer overflow");
|
|
23742
|
+
} catch {}
|
|
23743
|
+
state.delete(ws);
|
|
23744
|
+
return;
|
|
23745
|
+
}
|
|
23746
|
+
st.pending.push(frame);
|
|
23747
|
+
st.pendingBytes += size;
|
|
23725
23748
|
},
|
|
23726
23749
|
close(ws, code, reason) {
|
|
23727
23750
|
const st = state.get(ws);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-rpx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.22",
|
|
5
5
|
"description": "A modern and smart reverse proxy. Vite plugin.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"typecheck": "bunx tsc --noEmit"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@stacksjs/rpx": "0.11.
|
|
50
|
+
"@stacksjs/rpx": "0.11.22",
|
|
51
51
|
"@stacksjs/tlsx": "^0.13.9"
|
|
52
52
|
},
|
|
53
53
|
"simple-git-hooks": {
|