Skip to content

Commit 7cc3c64

Browse files
committed
fix super.so proxy
1 parent 4b4bf48 commit 7cc3c64

File tree

1 file changed

+12
-9
lines changed
  • apps/daimo-web/src/app/[...topLevelPage]

1 file changed

+12
-9
lines changed

apps/daimo-web/src/app/[...topLevelPage]/route.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,33 @@ export async function GET(request: Request) {
2222
console.log(`[WEB] got ${res.status} ${res.statusText}, ${resBody.size}b`);
2323

2424
// Rewrite /_next/... URLs to superSo/_next/...
25-
const ct = res.headers.get("content-type") || "";
26-
let retBody: string | Uint8Array;
27-
if (ct.includes("text/html")) {
25+
const contentType = res.headers.get("content-type") || "";
26+
let retBody: string | ArrayBuffer;
27+
if (contentType.includes("text/html")) {
2828
console.log(`[WEB] rewriting /_next/ URLs in ${upstreamUrl}`);
2929
const initHtml = await resBody.text();
3030
retBody = initHtml.replace(/\/_next\//g, `${superSo}/_next/`);
31+
} else if (contentType.startsWith("text/")) {
32+
retBody = await resBody.text();
3133
} else {
32-
retBody = await resBody.bytes();
34+
retBody = await resBody.arrayBuffer();
3335
}
3436

3537
const headers = new Headers();
3638
for (const [key, value] of res.headers.entries()) {
3739
if (key === "content-encoding") continue;
40+
if (key === "transfer-encoding") continue;
3841
if (key.startsWith("x-")) continue;
3942
headers.set(key, value);
4043
}
4144

42-
const bodyLength =
45+
const lengthStr =
4346
typeof retBody === "string"
44-
? new TextEncoder().encode(retBody).byteLength
45-
: retBody.byteLength;
46-
console.log(`[WEB] response type ${ct || "unknown"}, ${bodyLength}b`);
47+
? `${retBody.length}ch string`
48+
: `${retBody.byteLength}b buffer`;
49+
console.log(`[WEB] returning ${lengthStr}, ${headers.toString()}`);
4750

48-
return new Response(retBody as BodyInit, {
51+
return new Response(retBody, {
4952
status: res.status,
5053
statusText: res.statusText,
5154
headers,

0 commit comments

Comments
 (0)