Skip to content

Commit fb8babb

Browse files
author
Miriad
committed
debug: minimal OG test — single div, no nesting, isolate workers-og/WASM
1 parent 9668479 commit fb8babb

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed
Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
/**
2-
* Default OG image generation for generic pages.
2+
* Minimal OG image test — single div, no nesting.
3+
* If this fails, the problem is workers-og/fonts/WASM, not templates.
34
*/
45
import type { APIRoute } from "astro";
56
import { ImageResponse } from "workers-og";
6-
import { generateDefaultOgHtml, loadFonts, OG_CACHE_HEADER } from "../../../lib/og-utils";
7+
import { loadFonts } from "../../../lib/og-utils";
78

89
export const prerender = false;
910

1011
export const GET: APIRoute = async ({ url }) => {
1112
try {
12-
const title = url.searchParams.get("title") || "CodingCat.dev";
13-
const subtitle = url.searchParams.get("subtitle") || undefined;
14-
const html = generateDefaultOgHtml({ title, subtitle });
13+
const html = '<div style="display:flex;width:1200px;height:630px;background:#000;color:#fff;font-size:48px;align-items:center;justify-content:center">Hello World</div>';
1514

16-
// Use og() directly via ImageResponse + arrayBuffer() to catch stream errors
17-
const ogResponse = new ImageResponse(html, {
15+
const response = new ImageResponse(html, {
1816
width: 1200,
1917
height: 630,
2018
fonts: loadFonts(),
2119
});
2220

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-
);
21+
const buffer = await response.arrayBuffer();
22+
if (buffer.byteLength === 0) {
23+
return new Response(JSON.stringify({ error: "Empty buffer", htmlLength: html.length }), {
24+
status: 500,
25+
headers: { "Content-Type": "application/json" },
26+
});
3027
}
3128

32-
return new Response(body, {
33-
status: 200,
29+
return new Response(buffer, {
3430
headers: {
3531
"Content-Type": "image/png",
36-
"Content-Length": body.byteLength.toString(),
37-
"Cache-Control": OG_CACHE_HEADER,
32+
"Content-Length": buffer.byteLength.toString(),
3833
},
3934
});
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-
);
35+
} catch (e: any) {
36+
return new Response(JSON.stringify({ error: e.message, stack: e.stack }), {
37+
status: 500,
38+
headers: { "Content-Type": "application/json" },
39+
});
4540
}
4641
};

0 commit comments

Comments
 (0)