Fix OG image not rendering on Twitter/social shares

Root-level static files (og-image.png, favicon.svg, robots.txt, etc.)
were not served because the server only had routes for subdirectories.
Add a fetch fallback handler to serve any existing file from public/.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Paul Bakaus
2026-03-04 09:01:52 -08:00
co-authored by Claude Opus 4.6
parent 517fcfe47e
commit f3939c66e4
+23 -1
View File
@@ -49,7 +49,18 @@ const server = serve({
}
return new Response("Not Found", { status: 404 });
},
"/antipattern-examples/*": async (req) => {
const url = new URL(req.url);
const filePath = `./public${url.pathname}`;
const assetFile = file(filePath);
if (await assetFile.exists()) {
return new Response(assetFile, {
headers: { "Content-Type": "text/html" }
});
}
return new Response("Not Found", { status: 404 });
},
// API: Get all skills
"/api/skills": {
async GET() {
@@ -97,6 +108,17 @@ const server = serve({
},
},
// Serve root-level static files (og-image.png, favicon, robots.txt, etc.)
fetch(req) {
const url = new URL(req.url);
const filePath = `./public${url.pathname}`;
const staticFile = file(filePath);
if (staticFile.size > 0) {
return new Response(staticFile);
}
return new Response("Not Found", { status: 404 });
},
development: process.env.NODE_ENV !== "production",
});