File tree 3 files changed +26
-1
lines changed
packages/open-next/src/adapters
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " open-next " : patch
3
+ ---
4
+
5
+ Fix incorrect 200 with wrong buildId for page router
Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ export const processInternalEvent: ProcessInternalEvent = async (
42
42
const nextHeaders = addNextConfigHeaders ( event , ConfigHeaders ) ?? { } ;
43
43
44
44
let internalEvent = fixDataPage ( event , BuildId ) ;
45
+ // If we return InternalResult, it means that the build id is not correct
46
+ // We should return a 404
47
+ if ( "statusCode" in internalEvent ) {
48
+ return internalEvent ;
49
+ }
45
50
46
51
internalEvent = handleFallbackFalse ( internalEvent , PrerenderManifest ) ;
47
52
Original file line number Diff line number Diff line change @@ -239,9 +239,24 @@ export function handleRedirects(
239
239
}
240
240
}
241
241
242
- export function fixDataPage ( internalEvent : InternalEvent , buildId : string ) {
242
+ export function fixDataPage (
243
+ internalEvent : InternalEvent ,
244
+ buildId : string ,
245
+ ) : InternalEvent | InternalResult {
243
246
const { rawPath, query } = internalEvent ;
244
247
const dataPattern = `/_next/data/${ buildId } ` ;
248
+ // Return 404 for data requests that don't match the buildId
249
+ if ( rawPath . startsWith ( "/_next/data" ) && ! rawPath . startsWith ( dataPattern ) ) {
250
+ return {
251
+ type : internalEvent . type ,
252
+ statusCode : 404 ,
253
+ body : "{}" ,
254
+ headers : {
255
+ "Content-Type" : "application/json" ,
256
+ } ,
257
+ isBase64Encoded : false ,
258
+ } ;
259
+ }
245
260
246
261
if ( rawPath . startsWith ( dataPattern ) && rawPath . endsWith ( ".json" ) ) {
247
262
let newPath = rawPath . replace ( dataPattern , "" ) . replace ( / \. j s o n $ / , "" ) ;
You can’t perform that action at this time.
0 commit comments