Skip to content

Commit

Permalink
fix(vercel#39706): add avif support for node serve static
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 18, 2022
1 parent 06efbf4 commit e151ccd
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions 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,
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e151ccd

Please sign in to comment.