|
1 | 1 | /** |
2 | | - * Default OG image — debug version to surface runtime errors. |
| 2 | + * Default OG image — debug: returns raw HTML to inspect what Satori receives. |
3 | 3 | */ |
4 | 4 | import type { APIRoute } from "astro"; |
5 | | -import { ImageResponse } from "workers-og"; |
6 | | -import { generateDefaultOgHtml, loadFonts, OG_CACHE_HEADER } from "../../../lib/og-utils"; |
| 5 | +import { generateDefaultOgHtml } from "../../../lib/og-utils"; |
7 | 6 |
|
8 | 7 | export const prerender = false; |
9 | 8 |
|
10 | 9 | export const GET: APIRoute = async ({ url }) => { |
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 }); |
15 | | - const fonts = loadFonts(); |
| 10 | + const title = url.searchParams.get("title") || "CodingCat.dev"; |
| 11 | + const subtitle = url.searchParams.get("subtitle") || undefined; |
| 12 | + const html = generateDefaultOgHtml({ title, subtitle }); |
16 | 13 |
|
17 | | - // Debug: font info |
18 | | - const fontDebug = fonts.map((f: any) => ({ |
19 | | - name: f.name, |
20 | | - weight: f.weight, |
21 | | - dataType: typeof f.data, |
22 | | - isUint8Array: f.data instanceof Uint8Array, |
23 | | - isArrayBuffer: f.data instanceof ArrayBuffer, |
24 | | - length: f.data?.byteLength || f.data?.length || 0, |
25 | | - constructor: f.data?.constructor?.name, |
26 | | - first4Bytes: f.data ? Array.from(new Uint8Array(f.data instanceof ArrayBuffer ? f.data : f.data.buffer || f.data).slice(0, 4)) : null, |
27 | | - })); |
28 | | - |
29 | | - // Await the body to catch stream errors |
30 | | - const ogResponse = new ImageResponse(html, { |
31 | | - width: 1200, |
32 | | - height: 630, |
33 | | - fonts, |
34 | | - }); |
35 | | - |
36 | | - const body = await ogResponse.arrayBuffer(); |
37 | | - |
38 | | - if (body.byteLength === 0) { |
39 | | - return new Response( |
40 | | - JSON.stringify({ |
41 | | - error: "Empty body from ImageResponse", |
42 | | - fontDebug, |
43 | | - htmlSnippet: html.slice(0, 500), |
44 | | - }), |
45 | | - { status: 500, headers: { "Content-Type": "application/json" } } |
46 | | - ); |
47 | | - } |
48 | | - |
49 | | - return new Response(body, { |
50 | | - status: 200, |
51 | | - headers: { |
52 | | - "Content-Type": "image/png", |
53 | | - "Content-Length": body.byteLength.toString(), |
54 | | - }, |
55 | | - }); |
56 | | - } catch (error: any) { |
57 | | - return new Response( |
58 | | - JSON.stringify({ |
59 | | - error: error.message, |
60 | | - stack: error.stack, |
61 | | - name: error.name, |
62 | | - }), |
63 | | - { status: 500, headers: { "Content-Type": "application/json" } } |
64 | | - ); |
65 | | - } |
| 14 | + return new Response(html, { |
| 15 | + headers: { "Content-Type": "text/html" }, |
| 16 | + }); |
66 | 17 | }; |
0 commit comments