File tree 2 files changed +24
-9
lines changed
2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -144,12 +144,25 @@ describe('loadCustomRoutes', () => {
144
144
145
145
it ( 'does not insert assetPrefix rewrite for /_next/ paths when assetPrefix is absolute URL' , async ( ) => {
146
146
const customRoutes = await loadCustomRoutes ( {
147
- assetPrefix : 'https://example.com/custom-asset-prefix ' ,
147
+ assetPrefix : 'https://example.com' ,
148
148
} )
149
149
expect ( customRoutes . rewrites . beforeFiles ) . toEqual ( [ ] )
150
150
expect ( customRoutes . rewrites . afterFiles ) . toEqual ( [ ] )
151
151
} )
152
152
153
+ it ( 'automatically insert assetPrefix rewrite for /_next/ paths when assetPrefix is absolute URL with a path' , async ( ) => {
154
+ const customRoutes = await loadCustomRoutes ( {
155
+ assetPrefix : 'https://example.com/custom-asset-prefix' ,
156
+ } )
157
+ expect ( customRoutes . rewrites . beforeFiles ) . toEqual ( [
158
+ {
159
+ destination : '/_next/:path+' ,
160
+ source : '/custom-asset-prefix/_next/:path+' ,
161
+ } ,
162
+ ] )
163
+ expect ( customRoutes . rewrites . afterFiles ) . toEqual ( [ ] )
164
+ } )
165
+
153
166
it ( 'does not add rewrite when assetPrefix === basePath' , async ( ) => {
154
167
const customRoutes = await loadCustomRoutes ( {
155
168
assetPrefix : '/base' ,
Original file line number Diff line number Diff line change @@ -608,14 +608,16 @@ async function loadRewrites(config: NextConfig) {
608
608
prefix = new URL ( config . assetPrefix ) . pathname
609
609
}
610
610
611
- const assetPrefix = prefix . startsWith ( '/' ) ? prefix : `/${ prefix } `
612
- const basePath = config . basePath || ''
613
- // If these are the same, then this would result in an infinite rewrite.
614
- if ( assetPrefix !== basePath ) {
615
- maybeAssetPrefixRewrite . push ( {
616
- source : `${ assetPrefix } /_next/:path+` ,
617
- destination : `${ basePath } /_next/:path+` ,
618
- } )
611
+ if ( prefix && prefix !== '/' ) {
612
+ const assetPrefix = prefix . startsWith ( '/' ) ? prefix : `/${ prefix } `
613
+ const basePath = config . basePath || ''
614
+ // If these are the same, then this would result in an infinite rewrite.
615
+ if ( assetPrefix !== basePath ) {
616
+ maybeAssetPrefixRewrite . push ( {
617
+ source : `${ assetPrefix } /_next/:path+` ,
618
+ destination : `${ basePath } /_next/:path+` ,
619
+ } )
620
+ }
619
621
}
620
622
}
621
623
You can’t perform that action at this time.
0 commit comments