From e151ccd10e8b3bc3497c8b2ac0fd74b11c178572 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 19 Aug 2022 01:20:36 +0800 Subject: [PATCH] fix(#39706): add avif support for node serve static --- packages/next/server/serve-static.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/next/server/serve-static.ts b/packages/next/server/serve-static.ts index 7c2a441c6b75..c51236cf5f08 100644 --- a/packages/next/server/serve-static.ts +++ b/packages/next/server/serve-static.ts @@ -1,6 +1,12 @@ import { IncomingMessage, ServerResponse } from 'http' import send from 'next/dist/compiled/send' +// TODO: Remove this once "send" has updated the "mime", or next.js use custom version of "mime" +// Although "mime" has already add avif in version 2.4.7, "send" is still using mime@1.6.0 +send.mime.define({ + 'image/avif': ['avif'], +}) + export function serveStatic( req: IncomingMessage, res: ServerResponse, @@ -21,10 +27,6 @@ export function serveStatic( } export function getContentType(extWithoutDot: string): string | null { - if (extWithoutDot === 'avif') { - // TODO: update "mime" package - return 'image/avif' - } const { mime } = send if ('getType' in mime) { // 2.0 @@ -35,10 +37,6 @@ export function getContentType(extWithoutDot: string): string | null { } export function getExtension(contentType: string): string | null { - if (contentType === 'image/avif') { - // TODO: update "mime" package - return 'avif' - } const { mime } = send if ('getExtension' in mime) { // 2.0