cwresdev 0.1.6 → 0.1.9
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/bin/cwrespro.js +19 -0
- package/package.json +1 -1
- package/src/proxy.js +21 -3
package/bin/cwrespro.js
CHANGED
|
@@ -13,6 +13,25 @@ function openBrowser(url) {
|
|
|
13
13
|
child.unref();
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// Guard against Node.js v24+ internal undici assertion crash (ERR_ASSERTION
|
|
17
|
+
// in Parser.finish when upstream sockets close mid-stream). This is a known
|
|
18
|
+
// engine-level bug; swallowing it here keeps the dev server alive.
|
|
19
|
+
process.on("uncaughtException", (err) => {
|
|
20
|
+
if (
|
|
21
|
+
err &&
|
|
22
|
+
err.code === "ERR_ASSERTION" &&
|
|
23
|
+
err.stack &&
|
|
24
|
+
err.stack.includes("undici")
|
|
25
|
+
) {
|
|
26
|
+
process.stderr.write(
|
|
27
|
+
"[cwrespro] Warning: transient upstream connection reset (Node.js undici bug); ignoring.\n"
|
|
28
|
+
);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
throw err;
|
|
33
|
+
});
|
|
34
|
+
|
|
16
35
|
async function main() {
|
|
17
36
|
if (process.platform !== "win32") {
|
|
18
37
|
throw new Error("cwrespro currently supports Windows only.");
|
package/package.json
CHANGED
package/src/proxy.js
CHANGED
|
@@ -91,12 +91,22 @@ async function proxyRequest({ req, res, target, injectHtml = false, injectCookie
|
|
|
91
91
|
outHeaders.cookie = _stagingCookie;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const
|
|
94
|
+
const fetchOpts = {
|
|
95
95
|
method: req.method,
|
|
96
96
|
headers: outHeaders,
|
|
97
97
|
body,
|
|
98
98
|
redirect: "manual",
|
|
99
|
-
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
let upstream;
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
upstream = await fetch(target, fetchOpts);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
// Retry once – works around a transient Node.js v24 undici parser bug
|
|
107
|
+
// (ERR_ASSERTION in Parser.finish) that can reject the fetch promise.
|
|
108
|
+
upstream = await fetch(target, fetchOpts);
|
|
109
|
+
}
|
|
100
110
|
|
|
101
111
|
res.status(upstream.status);
|
|
102
112
|
|
|
@@ -132,7 +142,15 @@ async function proxyRequest({ req, res, target, injectHtml = false, injectCookie
|
|
|
132
142
|
return;
|
|
133
143
|
}
|
|
134
144
|
|
|
135
|
-
Readable.fromWeb(upstream.body)
|
|
145
|
+
const readable = Readable.fromWeb(upstream.body);
|
|
146
|
+
|
|
147
|
+
readable.on("error", (err) => {
|
|
148
|
+
if (!res.writableEnded) {
|
|
149
|
+
res.end();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
readable.pipe(res);
|
|
136
154
|
}
|
|
137
155
|
|
|
138
156
|
module.exports = {
|