|
1 | 1 | /** |
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. |
3 | 4 | */ |
4 | 5 | import type { APIRoute } from "astro"; |
5 | 6 | import { ImageResponse } from "workers-og"; |
6 | | -import { generateDefaultOgHtml, loadFonts, OG_CACHE_HEADER } from "../../../lib/og-utils"; |
| 7 | +import { loadFonts } from "../../../lib/og-utils"; |
7 | 8 |
|
8 | 9 | export const prerender = false; |
9 | 10 |
|
10 | 11 | export const GET: APIRoute = async ({ url }) => { |
11 | 12 | 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>'; |
15 | 14 |
|
16 | | - // Use og() directly via ImageResponse + arrayBuffer() to catch stream errors |
17 | | - const ogResponse = new ImageResponse(html, { |
| 15 | + const response = new ImageResponse(html, { |
18 | 16 | width: 1200, |
19 | 17 | height: 630, |
20 | 18 | fonts: loadFonts(), |
21 | 19 | }); |
22 | 20 |
|
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 | + }); |
30 | 27 | } |
31 | 28 |
|
32 | | - return new Response(body, { |
33 | | - status: 200, |
| 29 | + return new Response(buffer, { |
34 | 30 | headers: { |
35 | 31 | "Content-Type": "image/png", |
36 | | - "Content-Length": body.byteLength.toString(), |
37 | | - "Cache-Control": OG_CACHE_HEADER, |
| 32 | + "Content-Length": buffer.byteLength.toString(), |
38 | 33 | }, |
39 | 34 | }); |
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 | + }); |
45 | 40 | } |
46 | 41 | }; |
0 commit comments