Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Serve fallback project favicon when no icon file is found

Julius Marminge96bf54e293b4
diff --git a/apps/server/src/projectFaviconRoute.test.ts b/apps/server/src/projectFaviconRoute.test.ts
index e8b826d7b..34a430d97 100644
--- a/apps/server/src/projectFaviconRoute.test.ts
+++ b/apps/server/src/projectFaviconRoute.test.ts
@@ -152,4 +152,16 @@ describe("tryHandleProjectFaviconRequest", () => {
expect(response.body).toBe("<svg>brand-obj-order</svg>");
});
});
+
+ it("serves a fallback favicon when no icon exists", async () => {
+ const projectDir = makeTempDir("t3code-favicon-route-fallback-");
+
+ await withRouteServer(async (baseUrl) => {
+ const pathname = `/api/project-favicon?cwd=${encodeURIComponent(projectDir)}`;
+ const response = await request(baseUrl, pathname);
+ expect(response.statusCode).toBe(200);
+ expect(response.contentType).toContain("image/svg+xml");
+ expect(response.body).toContain('data-fallback="project-favicon"');
+ });
+ });
});
diff --git a/apps/server/src/projectFaviconRoute.ts b/apps/server/src/projectFaviconRoute.ts
index 4d66f0e86..cf234ad89 100644
--- a/apps/server/src/projectFaviconRoute.ts
+++ b/apps/server/src/projectFaviconRoute.ts
@@ -9,6 +9,8 @@ const FAVICON_MIME_TYPES: Record<string, string> = {
".ico": "image/x-icon",
};
+const FALLBACK_FAVICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#6b728080" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-fallback="project-favicon"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8l-2-2H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2Z"/></svg>`;
+
// Well-known favicon paths checked in order.
const FAVICON_CANDIDATES = [
"favicon.svg",
@@ -85,6 +87,14 @@ function serveFaviconFile(filePath: string, res: http.ServerResponse): void {
});
}
+function serveFallbackFavicon(res: http.ServerResponse): void {
+ res.writeHead(200, {
+ "Content-Type": "image/svg+xml",
+ "Cache-Control": "public, max-age=3600",
+ });
+ res.end(FALLBACK_FAVICON_SVG);
+}
+
export function tryHandleProjectFaviconRequest(url: URL, res: http.ServerResponse): boolean {
if (url.pathname !== "/api/project-favicon") {
return false;
@@ -118,8 +128,7 @@ export function tryHandleProjectFaviconRequest(url: URL, res: http.ServerRespons
const trySourceFiles = (index: number): void => {
if (index >= ICON_SOURCE_FILES.length) {
- res.writeHead(404, { "Content-Type": "text/plain" });
- res.end("No favicon found");
+ serveFallbackFavicon(res);
return;
}
const sourceFile = path.join(projectCwd, ICON_SOURCE_FILES[index]!);