From 1b9a776220cf9c0b107ac2d083c15c8ee732c92f Mon Sep 17 00:00:00 2001 From: daikei Date: Fri, 14 Apr 2023 16:18:50 +0000 Subject: [PATCH 1/2] replace koa-favicon with a small patch of code This should remove a needless dependency and replace it with a tiny, simple koa router --- packages/backend/src/server/web/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index 642a17d578..52b49c2a4a 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -8,13 +8,11 @@ import { readFileSync } from "node:fs"; import Koa from "koa"; import Router from "@koa/router"; import send from "koa-send"; -import favicon from "koa-favicon"; import views from "koa-views"; import sharp from "sharp"; import { createBullBoard } from "@bull-board/api"; import { BullAdapter } from "@bull-board/api/bullAdapter.js"; import { KoaAdapter } from "@bull-board/koa"; - import { In, IsNull } from "typeorm"; import { fetchMeta } from "@/misc/fetch-meta.js"; import config from "@/config/index.js"; @@ -98,8 +96,13 @@ app.use( }), ); -// Serve favicon -app.use(favicon(`${_dirname}/../../../assets/favicon.ico`)); +// Favicon Router +app.use(async (ctx, next) => { + if (ctx.path != '/favicon.ico') return next() + const meta = await fetchMeta(); + if (meta.iconUrl === "") ctx.body = readFileSync(`${_dirname}/../../../assets/favicon.ico`); + else ctx.redirect(meta.iconUrl) +}) // Common request handler app.use(async (ctx, next) => { From c959d4185c296bd711b96a0f7c01898b54c4e95c Mon Sep 17 00:00:00 2001 From: daikei Date: Fri, 14 Apr 2023 16:20:27 +0000 Subject: [PATCH 2/2] remove koa-favicon --- packages/backend/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index a03d6d35be..b02af2c033 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -75,7 +75,6 @@ "koa": "2.13.4", "koa-body": "^6.0.1", "koa-bodyparser": "4.3.0", - "koa-favicon": "2.1.0", "koa-json-body": "5.3.0", "koa-logger": "3.2.1", "koa-mount": "4.0.0",