Skip to content

Commit a698e1b

Browse files
committed
move legacy ipx redirect to adapter as well
1 parent 273fd1c commit a698e1b

File tree

4 files changed

+14
-125
lines changed

4 files changed

+14
-125
lines changed

src/adapter/image-cdn.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ function generateRegexFromPattern(pattern: string): string {
2121
}
2222

2323
export function onBuildComplete(ctx: OnBuildCompleteContext, frameworksAPIConfigArg: any) {
24-
let frameworksAPIConfig: any = frameworksAPIConfigArg
24+
const frameworksAPIConfig: any = frameworksAPIConfigArg ?? {}
25+
26+
// when migrating from @netlify/plugin-nextjs@4 image redirect to ipx might be cached in the browser
27+
frameworksAPIConfig.redirects ??= []
28+
frameworksAPIConfig.redirects.push({
29+
from: '/_ipx/*',
30+
// w and q are too short to be used as params with id-length rule
31+
// but we are forced to do so because of the next/image loader decides on their names
32+
// eslint-disable-next-line id-length
33+
query: { url: ':url', w: ':width', q: ':quality' },
34+
to: '/.netlify/images?url=:url&w=:width&q=:quality',
35+
status: 200,
36+
})
2537

2638
const { images } = ctx.config
2739
if (images.loader === 'custom' && images.loaderFile === NETLIFY_IMAGE_LOADER_FILE) {
@@ -83,7 +95,6 @@ export function onBuildComplete(ctx: OnBuildCompleteContext, frameworksAPIConfig
8395

8496
if (remoteImageSources.length !== 0) {
8597
// https://docs.netlify.com/build/frameworks/frameworks-api/#images
86-
frameworksAPIConfig ??= {}
8798
frameworksAPIConfig.images ??= {}
8899
frameworksAPIConfig.images.remote_images = remoteImageSources
89100
}

src/build/image-cdn.test.ts

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/build/image-cdn.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
} from './build/content/static.js'
1818
import { clearStaleEdgeHandlers, createEdgeHandlers } from './build/functions/edge.js'
1919
import { clearStaleServerHandlers, createServerHandler } from './build/functions/server.js'
20-
import { setLegacyIpxRewrite } from './build/image-cdn.js'
2120
import { PluginContext } from './build/plugin-context.js'
2221
import {
2322
verifyAdvancedAPIRoutes,
@@ -89,7 +88,7 @@ export const onBuild = async (options: NetlifyPluginOptions) => {
8988

9089
// static exports only need to be uploaded to the CDN and setup /_next/image handler
9190
if (ctx.buildConfig.output === 'export') {
92-
return Promise.all([copyStaticExport(ctx), setHeadersConfig(ctx), setLegacyIpxRewrite(ctx)])
91+
return Promise.all([copyStaticExport(ctx), setHeadersConfig(ctx)])
9392
}
9493

9594
await verifyAdvancedAPIRoutes(ctx)
@@ -102,7 +101,6 @@ export const onBuild = async (options: NetlifyPluginOptions) => {
102101
createServerHandler(ctx),
103102
createEdgeHandlers(ctx),
104103
setHeadersConfig(ctx),
105-
setLegacyIpxRewrite(ctx),
106104
])
107105
})
108106
}

0 commit comments

Comments
 (0)