Skip to content

Commit 014d6db

Browse files
authored
fix(favicon): 添加 favicon 路由处理逻辑 (#445)
1 parent f4e058b commit 014d6db

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

server/src/_worker.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { drizzle } from "drizzle-orm/d1";
22
import { createHonoApp } from "./core/hono-app";
33
import { CacheImpl } from "./utils/cache";
4+
import { FaviconService } from "./services/favicon";
5+
import { Hono } from "hono";
6+
import type { Variables } from "hono/types";
7+
import { initContainerMiddleware, timingMiddleware } from "./core/hono-middleware";
48

59
// Create app instance (singleton)
610
let app: ReturnType<typeof createHonoApp> | null = null;
@@ -20,9 +24,22 @@ export default {
2024
const url = new URL(request.url);
2125
const path = url.pathname;
2226

27+
if (path.startsWith('/favicon.ico')) {
28+
29+
const app = new Hono<{
30+
Bindings: Env;
31+
Variables: Variables;
32+
}>();
33+
34+
app.use('*', timingMiddleware);
35+
app.use('*', initContainerMiddleware);
36+
app.route('/', FaviconService());
37+
return await app.fetch(request, env);
38+
}
39+
2340
// Handle RSS feeds directly (native RSS support at root path)
2441
// Matches: /rss.xml, /atom.xml, /rss.json, /feed.json, /feed.xml
25-
if (path.match(/^\/(rss\.xml|atom\.xml|rss\.json|feed\.json|feed\.xml)$/) || path.startsWith('/api/') || path.startsWith('/favicon.ico')) {
42+
if (path.match(/^\/(rss\.xml|atom\.xml|rss\.json|feed\.json|feed\.xml)$/) || path.startsWith('/api/')) {
2643
const honoApp = getApp();
2744
return await honoApp.fetch(request, env);
2845
}

0 commit comments

Comments
 (0)