@@ -21,7 +21,9 @@ export async function middleware(req: NextRequest) {
21
21
}
22
22
23
23
const request = new MiddlewareRequest ( req )
24
- if ( pathname . startsWith ( '/static' ) ) {
24
+
25
+ // skipMiddlewareUrlNormalize next config option is used so we have to try to match both html path and data blob path
26
+ if ( pathname . startsWith ( '/static' ) || pathname . endsWith ( '/static.json' ) ) {
25
27
// Unlike NextResponse.next(), this actually sends the request to the origin
26
28
const res = await request . next ( )
27
29
const message = `This was static (& escaping test &) but has been transformed in ${ req . geo ?. city } `
@@ -36,7 +38,8 @@ export async function middleware(req: NextRequest) {
36
38
return res
37
39
}
38
40
39
- if ( pathname . startsWith ( '/request-rewrite' ) ) {
41
+ // skipMiddlewareUrlNormalize next config option is used so we have to try to match both html path and data blob path
42
+ if ( pathname . startsWith ( '/request-rewrite' ) || pathname . endsWith ( '/request-rewrite.json' ) ) {
40
43
// request.rewrite() should return the MiddlewareResponse object instead of the Response object.
41
44
const res = await request . rewrite ( '/static-rewrite' )
42
45
const message = `This was static (& escaping test &) but has been transformed in ${ req . geo ?. city } `
@@ -100,6 +103,10 @@ export async function middleware(req: NextRequest) {
100
103
return response
101
104
}
102
105
106
+ if ( pathname . includes ( 'locale-preserving-rewrite' ) ) {
107
+ return NextResponse . rewrite ( new URL ( '/locale-test' , req . url ) )
108
+ }
109
+
103
110
if ( pathname . startsWith ( '/shows' ) ) {
104
111
if ( pathname . startsWith ( '/shows/222' ) ) {
105
112
response = NextResponse . next ( )
@@ -151,6 +158,7 @@ export const config = {
151
158
matcher : [
152
159
'/api/:all*' ,
153
160
'/headers' ,
161
+ '/:all*/locale-preserving-rewrite' ,
154
162
'/cookies/:path*' ,
155
163
{ source : '/static' } ,
156
164
{ source : '/request-rewrite' } ,
0 commit comments