diff --git a/src/home.ts b/src/home.ts index 08c7b41..067c43b 100644 --- a/src/home.ts +++ b/src/home.ts @@ -109,3 +109,24 @@ export function home(allowedOrigins: string): Response { `); } + +/** anything that isn't / or /card: bufo shrugs. */ +export function notFound(): Response { + const body = ` + + + + +not found + + + +
+bufo shrugging, on a card +

nothing here. cards lives at / and makes them at /card.

+
+ + +`; + return new Response(body, { status: 404, headers: { "content-type": "text/html;charset=UTF-8" } }); +} diff --git a/src/index.ts b/src/index.ts index 42cb72f..c44274b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { animatedCard, firstFrame, isGif } from "./animated.ts"; -import { home } from "./home.ts"; +import { home, notFound } from "./home.ts"; import { MAX_ANIMATED_BYTES, MAX_INPUT_BYTES } from "./layout.ts"; import { stillCard } from "./still.ts"; @@ -47,7 +47,7 @@ export default { async fetch(request, env, ctx): Promise { const url = new URL(request.url); if (url.pathname === "/") return home(env.ALLOWED_ORIGINS); - if (url.pathname !== "/card") return new Response("not found\n", { status: 404 }); + if (url.pathname !== "/card") return notFound(); if (request.method !== "GET" && request.method !== "HEAD") return new Response(null, { status: 405 }); const src = allowed(url.searchParams.get("src") ?? "", env.ALLOWED_ORIGINS); if (!src) return new Response("src must be an image url on an allowed origin\n", { status: 400 });