From 42c7f73bf5323abf5e474f576114e4e19ce8a8d9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 20 Oct 2024 06:22:27 +0200 Subject: [PATCH] Serve a favicon --- src/deno/router.ts | 9 +++++++-- src/dv/favicon.ts | 18 ++++++++++++++++++ src/dv/hostMeta.ts | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/dv/favicon.ts diff --git a/src/deno/router.ts b/src/deno/router.ts index 9ec7246..ece7f03 100644 --- a/src/deno/router.ts +++ b/src/deno/router.ts @@ -1,6 +1,7 @@ import { getLogger } from "@logtape/logtape" import { handleHostMeta } from "../dv/hostMeta.ts" import { DotinoVeloce } from "../dv/dotinoVeloce.ts" +import { handleFavicon } from "../dv/favicon.ts" const l = getLogger(["dotino-veloce", "deno", "router"]) @@ -21,15 +22,19 @@ export function createRouter(ap: DotinoVeloce) { const pathname = url.pathname l.debug`Request's pathname is: ${pathname}` + if (url.pathname === "/favicon.ico") { + l.debug`Delegating handling to favicon handler...` + return await handleFavicon() + } if (url.pathname === "/.well-known/host-meta") { l.debug`Delegating handling to host-meta generator...` - return handleHostMeta(url.origin) + return await handleHostMeta(url.origin) } else { l.debug`Delegating request to Fedify...` - return ap.federation.fetch( + return await ap.federation.fetch( request, { contextData: undefined, diff --git a/src/dv/favicon.ts b/src/dv/favicon.ts new file mode 100644 index 0000000..04e9045 --- /dev/null +++ b/src/dv/favicon.ts @@ -0,0 +1,18 @@ +import { getLogger } from "@logtape/logtape" + + +const l = getLogger(["dotino-veloce", "ap", "favicon"]) + + +export async function handleFavicon(): Promise { + l.info`Returning favicon...` + + return new Response( + await Deno.readFile(".media/icon-128x128_round.png"), + { + headers: { + "Content-Type": "image/png", + }, + }, + ) +} diff --git a/src/dv/hostMeta.ts b/src/dv/hostMeta.ts index e5986ea..d7f6a1d 100644 --- a/src/dv/hostMeta.ts +++ b/src/dv/hostMeta.ts @@ -4,7 +4,8 @@ import { getLogger } from "@logtape/logtape" const l = getLogger(["dotino-veloce", "ap", "hostMeta"]) -export function handleHostMeta(origin: string): Response { +// deno-lint-ignore require-await +export async function handleHostMeta(origin: string): Promise { l.info`Creating host-meta definition for: ${origin}` // Akkoma expects host-meta to be correctly setup