1
1
import { cp , mkdir , readFile , rm , writeFile } from 'node:fs/promises'
2
2
import { dirname , join } from 'node:path'
3
3
4
- import type { Manifest , ManifestFunction } from '@netlify/edge-functions'
4
+ import type { IntegrationsConfig , Manifest , ManifestFunction } from '@netlify/edge-functions'
5
5
import { glob } from 'fast-glob'
6
6
import type { EdgeFunctionDefinition as NextDefinition } from 'next/dist/build/webpack/plugins/middleware-plugin.js'
7
7
import { pathToRegexp } from 'path-to-regexp'
@@ -160,21 +160,25 @@ const getHandlerName = ({ name }: Pick<NextDefinition, 'name'>): string =>
160
160
const buildHandlerDefinition = (
161
161
ctx : PluginContext ,
162
162
{ name, matchers, page } : NextDefinition ,
163
- ) : Array < ManifestFunction > => {
164
- const fun = getHandlerName ( { name } )
165
- const funName = name . endsWith ( 'middleware' )
163
+ ) : ManifestFunction & IntegrationsConfig => {
164
+ const functionHandlerName = getHandlerName ( { name } )
165
+ const functionName = name . endsWith ( 'middleware' )
166
166
? 'Next.js Middleware Handler'
167
167
: `Next.js Edge Handler: ${ page } `
168
168
const cache = name . endsWith ( 'middleware' ) ? undefined : ( 'manual' as const )
169
169
const generator = `${ ctx . pluginName } @${ ctx . pluginVersion } `
170
-
171
- return augmentMatchers ( matchers , ctx ) . map ( ( matcher ) => ( {
172
- function : fun ,
173
- name : funName ,
174
- pattern : matcher . regexp ,
170
+ const i18nAugmentedMatchers = augmentMatchers ( matchers , ctx )
171
+ const combinedEdgeHandlerRegex = i18nAugmentedMatchers
172
+ . map ( ( matcher ) => `(${ matcher . regexp } )` )
173
+ . join ( '|' )
174
+
175
+ return {
176
+ function : functionHandlerName ,
177
+ name : functionName ,
178
+ pattern : combinedEdgeHandlerRegex ,
175
179
cache,
176
180
generator,
177
- } ) )
181
+ }
178
182
}
179
183
180
184
export const clearStaleEdgeHandlers = async ( ctx : PluginContext ) => {
@@ -183,10 +187,7 @@ export const clearStaleEdgeHandlers = async (ctx: PluginContext) => {
183
187
184
188
export const createEdgeHandlers = async ( ctx : PluginContext ) => {
185
189
const nextManifest = await ctx . getMiddlewareManifest ( )
186
- const nextDefinitions = [
187
- ...Object . values ( nextManifest . middleware ) ,
188
- // ...Object.values(nextManifest.functions)
189
- ]
190
+ const nextDefinitions = [ ...Object . values ( nextManifest . middleware ) ]
190
191
await Promise . all ( nextDefinitions . map ( ( def ) => createEdgeHandler ( ctx , def ) ) )
191
192
192
193
const netlifyDefinitions = nextDefinitions . flatMap ( ( def ) => buildHandlerDefinition ( ctx , def ) )
0 commit comments