Skip to content

Commit 9668479

Browse files
author
Miriad
committed
debug: restore rendering with arrayBuffer() error capture on default.png
1 parent ed77f70 commit 9668479

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed
Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
11
/**
2-
* Default OG image — debug: returns raw HTML to inspect what Satori receives.
2+
* Default OG image generation for generic pages.
33
*/
44
import type { APIRoute } from "astro";
5-
import { generateDefaultOgHtml } from "../../../lib/og-utils";
5+
import { ImageResponse } from "workers-og";
6+
import { generateDefaultOgHtml, loadFonts, OG_CACHE_HEADER } from "../../../lib/og-utils";
67

78
export const prerender = false;
89

910
export const GET: APIRoute = async ({ url }) => {
10-
const title = url.searchParams.get("title") || "CodingCat.dev";
11-
const subtitle = url.searchParams.get("subtitle") || undefined;
12-
const html = generateDefaultOgHtml({ title, subtitle });
11+
try {
12+
const title = url.searchParams.get("title") || "CodingCat.dev";
13+
const subtitle = url.searchParams.get("subtitle") || undefined;
14+
const html = generateDefaultOgHtml({ title, subtitle });
1315

14-
return new Response(html, {
15-
headers: { "Content-Type": "text/html" },
16-
});
16+
// Use og() directly via ImageResponse + arrayBuffer() to catch stream errors
17+
const ogResponse = new ImageResponse(html, {
18+
width: 1200,
19+
height: 630,
20+
fonts: loadFonts(),
21+
});
22+
23+
const body = await ogResponse.arrayBuffer();
24+
25+
if (body.byteLength === 0) {
26+
return new Response(
27+
JSON.stringify({ error: "Empty body", htmlLength: html.length }),
28+
{ status: 500, headers: { "Content-Type": "application/json" } }
29+
);
30+
}
31+
32+
return new Response(body, {
33+
status: 200,
34+
headers: {
35+
"Content-Type": "image/png",
36+
"Content-Length": body.byteLength.toString(),
37+
"Cache-Control": OG_CACHE_HEADER,
38+
},
39+
});
40+
} catch (error: any) {
41+
return new Response(
42+
JSON.stringify({ error: error.message, stack: error.stack }),
43+
{ status: 500, headers: { "Content-Type": "application/json" } }
44+
);
45+
}
1746
};

0 commit comments

Comments
 (0)