add fetch() shim to proxy cross-origin requests through server

This commit is contained in:
Nystik
2026-03-24 01:06:30 +01:00
parent df9d53984b
commit d5027795e9
4 changed files with 164 additions and 3 deletions

View File

@@ -28,10 +28,19 @@ router.post("/", async (req, res) => {
const upstream = await fetch(url, fetchOpts);
const respBody = Buffer.from(await upstream.arrayBuffer());
// Forward response headers
// Forward response headers, stripping hop-by-hop / encoding headers
// since the body is already decompressed by Node's fetch
const skipHeaders = new Set([
"content-encoding",
"transfer-encoding",
"content-length",
"connection",
]);
const respHeaders = {};
upstream.headers.forEach((val, key) => {
respHeaders[key] = val;
if (!skipHeaders.has(key)) {
respHeaders[key] = val;
}
});
res.json({