@@ -10,7 +10,8 @@ import type { MiddlewareManifest } from 'next/dist/build/webpack/plugins/middlew
10
10
import type { RouteHas } from 'next/dist/lib/load-custom-routes'
11
11
import { outdent } from 'outdent'
12
12
13
- import { getRequiredServerFiles } from './config'
13
+ import { getRequiredServerFiles , NextConfig } from './config'
14
+ import { makeLocaleOptional , stripLookahead } from './matchers'
14
15
15
16
// This is the format as of [email protected]
16
17
interface EdgeFunctionDefinitionV1 {
@@ -132,10 +133,12 @@ const writeEdgeFunction = async ({
132
133
edgeFunctionDefinition,
133
134
edgeFunctionRoot,
134
135
netlifyConfig,
136
+ nextConfig,
135
137
} : {
136
138
edgeFunctionDefinition : EdgeFunctionDefinition
137
139
edgeFunctionRoot : string
138
140
netlifyConfig : NetlifyConfig
141
+ nextConfig : NextConfig
139
142
} ) : Promise <
140
143
Array < {
141
144
function : string
@@ -165,14 +168,22 @@ const writeEdgeFunction = async ({
165
168
// The v1 middleware manifest has a single regexp, but the v2 has an array of matchers
166
169
if ( 'regexp' in edgeFunctionDefinition ) {
167
170
matchers . push ( { regexp : edgeFunctionDefinition . regexp } )
171
+ } else if ( nextConfig . i18n ) {
172
+ matchers . push (
173
+ ...edgeFunctionDefinition . matchers . map ( ( matcher ) => ( {
174
+ ...matcher ,
175
+ regexp : makeLocaleOptional ( matcher . regexp ) ,
176
+ } ) ) ,
177
+ )
168
178
} else {
169
179
matchers . push ( ...edgeFunctionDefinition . matchers )
170
180
}
181
+
171
182
await writeJson ( join ( edgeFunctionDir , 'matchers.json' ) , matchers )
172
183
173
184
// We add a defintion for each matching path
174
185
return matchers . map ( ( matcher ) => {
175
- const pattern = matcher . regexp
186
+ const pattern = stripLookahead ( matcher . regexp )
176
187
return { function : name , pattern, name : edgeFunctionDefinition . name }
177
188
} )
178
189
}
@@ -258,6 +269,7 @@ export const writeEdgeFunctions = async (netlifyConfig: NetlifyConfig) => {
258
269
edgeFunctionDefinition,
259
270
edgeFunctionRoot,
260
271
netlifyConfig,
272
+ nextConfig,
261
273
} )
262
274
manifest . functions . push ( ...functionDefinitions )
263
275
}
@@ -270,6 +282,7 @@ export const writeEdgeFunctions = async (netlifyConfig: NetlifyConfig) => {
270
282
edgeFunctionDefinition,
271
283
edgeFunctionRoot,
272
284
netlifyConfig,
285
+ nextConfig,
273
286
} )
274
287
manifest . functions . push ( ...functionDefinitions )
275
288
}
0 commit comments