@@ -461,17 +461,19 @@ export const writeEdgeFunctions = async ({
461
461
...matchers . map ( ( matcher ) => middlewareMatcherToEdgeFunctionDefinition ( matcher , functionName ) ) ,
462
462
)
463
463
}
464
+ // Functions (i.e. not middleware, but edge SSR and API routes)
464
465
if ( typeof middlewareManifest . functions === 'object' ) {
465
466
// When using the app dir, we also need to check if the EF matches a page
466
467
const appPathRoutesManifest = await loadAppPathRoutesManifest ( netlifyConfig )
467
468
469
+ // A map of all route pages to their page regex. This is used for pages dir and appDir.
468
470
const pageRegexMap = new Map (
469
471
[ ...( routesManifest . dynamicRoutes || [ ] ) , ...( routesManifest . staticRoutes || [ ] ) ] . map ( ( route ) => [
470
472
route . page ,
471
473
route . regex ,
472
474
] ) ,
473
475
)
474
-
476
+ // Create a map of pages-dir routes to their data route regex (appDir uses the same route as the HTML)
475
477
const dataRoutesMap = new Map (
476
478
[ ...( routesManifest . dataRoutes || [ ] ) ] . map ( ( route ) => [ route . page , route . dataRouteRegex ] ) ,
477
479
)
@@ -497,6 +499,7 @@ export const writeEdgeFunctions = async ({
497
499
// cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir
498
500
cache : usesAppDir ? 'manual' : undefined ,
499
501
} )
502
+ // pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too
500
503
const dataRoute = dataRoutesMap . get ( edgeFunctionDefinition . page )
501
504
if ( dataRoute ) {
502
505
manifest . functions . push ( {
0 commit comments