From f83a01b9101bc4be978beb2a4b5d1019b19e4340 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 3 Oct 2023 11:10:39 +0200 Subject: [PATCH] move from serve-favicon to a custom route to support svg --- code/lib/core-server/package.json | 2 - .../core-server/src/utils/server-statics.ts | 8 ++-- code/yarn.lock | 38 ------------------- 3 files changed, 4 insertions(+), 44 deletions(-) diff --git a/code/lib/core-server/package.json b/code/lib/core-server/package.json index 8c10b00e73ed..c249bc634c35 100644 --- a/code/lib/core-server/package.json +++ b/code/lib/core-server/package.json @@ -94,7 +94,6 @@ "prompts": "^2.4.0", "read-pkg-up": "^7.0.1", "semver": "^7.3.7", - "serve-favicon": "^2.5.0", "telejson": "^7.2.0", "tiny-invariant": "^1.3.1", "ts-dedent": "^2.0.0", @@ -108,7 +107,6 @@ "@types/compression": "^1.7.0", "@types/ip": "^1.1.0", "@types/node-fetch": "^2.5.7", - "@types/serve-favicon": "^2.5.2", "@types/ws": "^8", "boxen": "^5.1.2", "jest-os-detection": "^1.3.1", diff --git a/code/lib/core-server/src/utils/server-statics.ts b/code/lib/core-server/src/utils/server-statics.ts index b2d5a5e3cbce..19d569cfcc06 100644 --- a/code/lib/core-server/src/utils/server-statics.ts +++ b/code/lib/core-server/src/utils/server-statics.ts @@ -3,16 +3,16 @@ import type { Options, StorybookConfig } from '@storybook/types'; import { getDirectoryFromWorkingDir } from '@storybook/core-common'; import { ConflictingStaticDirConfigError } from '@storybook/core-events/server-errors'; import chalk from 'chalk'; +import type { Router } from 'express'; import express from 'express'; import { pathExists } from 'fs-extra'; -import path from 'path'; -import favicon from 'serve-favicon'; +import path, { basename } from 'path'; import isEqual from 'lodash/isEqual.js'; import { dedent } from 'ts-dedent'; import { defaultStaticDirs } from './constants'; -export async function useStatics(router: any, options: Options) { +export async function useStatics(router: Router, options: Options) { const staticDirs = (await options.presets.apply('staticDirs')) ?? []; const faviconPath = await options.presets.apply('favicon'); @@ -54,7 +54,7 @@ export async function useStatics(router: any, options: Options) { ); } - router.use(favicon(faviconPath)); + router.get(`/${basename(faviconPath)}`, (req, res) => res.sendFile(faviconPath)); } export const parseStaticDir = async (arg: string) => { diff --git a/code/yarn.lock b/code/yarn.lock index 704c48e55acf..af6301afc76b 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6853,7 +6853,6 @@ __metadata: "@types/node-fetch": ^2.5.7 "@types/pretty-hrtime": ^1.0.0 "@types/semver": ^7.3.4 - "@types/serve-favicon": ^2.5.2 "@types/ws": ^8 better-opn: ^3.0.2 boxen: ^5.1.2 @@ -6874,7 +6873,6 @@ __metadata: prompts: ^2.4.0 read-pkg-up: ^7.0.1 semver: ^7.3.7 - serve-favicon: ^2.5.0 slash: ^5.0.0 telejson: ^7.2.0 tiny-invariant: ^1.3.1 @@ -9645,15 +9643,6 @@ __metadata: languageName: node linkType: hard -"@types/serve-favicon@npm:^2.5.2": - version: 2.5.4 - resolution: "@types/serve-favicon@npm:2.5.4" - dependencies: - "@types/express": "*" - checksum: 60bb648eff8bba7f589e9a2027879c39c137c96e1afafb6a09cb220477c1ebe74c3ce4293c52724592f04e3278950b82741f449c8517a432c163107333a0d6b8 - languageName: node - linkType: hard - "@types/serve-index@npm:^1.9.1": version: 1.9.1 resolution: "@types/serve-index@npm:1.9.1" @@ -23671,13 +23660,6 @@ __metadata: languageName: node linkType: hard -"ms@npm:2.1.1": - version: 2.1.1 - resolution: "ms@npm:2.1.1" - checksum: 056140c631e740369fa21142417aba1bd629ab912334715216c666eb681c8f015c622dd4e38bc1d836b30852b05641331661703af13a0397eb0ca420fc1e75d9 - languageName: node - linkType: hard - "ms@npm:2.1.2": version: 2.1.2 resolution: "ms@npm:2.1.2" @@ -28475,13 +28457,6 @@ __metadata: languageName: node linkType: hard -"safe-buffer@npm:5.1.1": - version: 5.1.1 - resolution: "safe-buffer@npm:5.1.1" - checksum: 1c233bd105deeba3c9a8911ed4ec24ba45adbb51fec02f7944a10a202c38e3df4ef2b524bdeb55f2e4f8c77c13b2959e2e2e6022e5d99acdd70633b5f7e138cf - languageName: node - linkType: hard - "safe-buffer@npm:5.1.2, safe-buffer@npm:~5.1.0, safe-buffer@npm:~5.1.1": version: 5.1.2 resolution: "safe-buffer@npm:5.1.2" @@ -28790,19 +28765,6 @@ __metadata: languageName: node linkType: hard -"serve-favicon@npm:^2.5.0": - version: 2.5.0 - resolution: "serve-favicon@npm:2.5.0" - dependencies: - etag: ~1.8.1 - fresh: 0.5.2 - ms: 2.1.1 - parseurl: ~1.3.2 - safe-buffer: 5.1.1 - checksum: 7244ced3c46f8dfde591dc801f1e21ebc8fa07c4870cbbaee3ce37104b3aad32858e674e251a8ed4837867ea0dd67cb734b485ae5a7b0895cb6022f8b8c79303 - languageName: node - linkType: hard - "serve-index@npm:^1.9.1": version: 1.9.1 resolution: "serve-index@npm:1.9.1"