File tree Expand file tree Collapse file tree 3 files changed +15
-8
lines changed
open-next/src/core/routing
tests-unit/tests/core/routing Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @opennextjs/aws " : patch
3+ " tests-unit " : patch
4+ ---
5+
6+ fix dataRoutes omitting basePath in page router (#897 )
Original file line number Diff line number Diff line change @@ -381,8 +381,8 @@ export function fixDataPage(
381381 buildId : string ,
382382) : InternalEvent | InternalResult {
383383 const { rawPath, query } = internalEvent ;
384- const dataPattern = ` ${ NextConfig . basePath ?? "" } /_next/data/ ${ buildId } ` ;
385-
384+ const basePath = NextConfig . basePath ?? "" ;
385+ const dataPattern = ` ${ basePath } /_next/data/ ${ buildId } ` ;
386386 // Return 404 for data requests that don't match the buildId
387387 if ( rawPath . startsWith ( "/_next/data" ) && ! rawPath . startsWith ( dataPattern ) ) {
388388 return {
@@ -397,9 +397,9 @@ export function fixDataPage(
397397 }
398398
399399 if ( rawPath . startsWith ( dataPattern ) && rawPath . endsWith ( ".json" ) ) {
400- const newPath = rawPath
400+ const newPath = ` ${ basePath } ${ rawPath
401401 . slice ( dataPattern . length , - ".json" . length )
402- . replace ( / ^ \/ i n d e x $ / , "/" ) ;
402+ . replace ( / ^ \/ i n d e x $ / , "/" ) } ` ;
403403 query . __nextDataReq = "1" ;
404404
405405 return {
Original file line number Diff line number Diff line change @@ -598,18 +598,19 @@ describe("fixDataPage", () => {
598598 } ) ;
599599
600600 it ( "should remove json extension from data requests (with base path) and add __nextDataReq to query" , ( ) => {
601- NextConfig . basePath = "/base" ;
601+ const mockBasePath = "/base" ;
602+ NextConfig . basePath = mockBasePath ;
602603
603604 const event = createEvent ( {
604- url : " https://on/base/ _next/data/abc/test/file.json?hello=world" ,
605+ url : ` https://on${ mockBasePath } / _next/data/abc/test/file.json?hello=world` ,
605606 } ) ;
606607
607608 const response = fixDataPage ( event , "abc" ) ;
608609
609610 expect ( response ) . toEqual ( {
610611 ...event ,
611- rawPath : " /test/file" ,
612- url : " https://on/test/file?hello=world&__nextDataReq=1" ,
612+ rawPath : ` ${ mockBasePath } /test/file` ,
613+ url : ` https://on${ mockBasePath } /test/file?hello=world&__nextDataReq=1` ,
613614 } ) ;
614615
615616 NextConfig . basePath = undefined ;
You can’t perform that action at this time.
0 commit comments