({
config,
baseDir,
projectDir,
entryPath,
nextVersion,
nodeVersion,
lstatSema,
lstatResults,
pageExtensions,
routesManifest,
outputDirectory,
prerenderBypassToken,
isCorrectMiddlewareOrder,
functionsConfigManifest,
requiredServerFilesManifest,
}: {
config: Config;
baseDir: string;
projectDir: string;
lstatSema: Sema;
lstatResults: { [key: string]: ReturnType<typeof lstat> };
entryPath: string;
nodeVersion: string;
pageExtensions: string[];
nextVersion: string;
outputDirectory: string;
prerenderBypassToken: string;
isCorrectMiddlewareOrder: boolean;
routesManifest: RoutesManifest;
functionsConfigManifest?: FunctionsConfigManifestV1;
requiredServerFilesManifest: NextRequiredServerFilesManifest;
})
| 3956 | } |
| 3957 | |
| 3958 | export async function getNodeMiddleware({ |
| 3959 | config, |
| 3960 | baseDir, |
| 3961 | projectDir, |
| 3962 | entryPath, |
| 3963 | nextVersion, |
| 3964 | nodeVersion, |
| 3965 | lstatSema, |
| 3966 | lstatResults, |
| 3967 | pageExtensions, |
| 3968 | routesManifest, |
| 3969 | outputDirectory, |
| 3970 | prerenderBypassToken, |
| 3971 | isCorrectMiddlewareOrder, |
| 3972 | functionsConfigManifest, |
| 3973 | requiredServerFilesManifest, |
| 3974 | }: { |
| 3975 | config: Config; |
| 3976 | baseDir: string; |
| 3977 | projectDir: string; |
| 3978 | lstatSema: Sema; |
| 3979 | lstatResults: { [key: string]: ReturnType<typeof lstat> }; |
| 3980 | entryPath: string; |
| 3981 | nodeVersion: string; |
| 3982 | pageExtensions: string[]; |
| 3983 | nextVersion: string; |
| 3984 | outputDirectory: string; |
| 3985 | prerenderBypassToken: string; |
| 3986 | isCorrectMiddlewareOrder: boolean; |
| 3987 | routesManifest: RoutesManifest; |
| 3988 | functionsConfigManifest?: FunctionsConfigManifestV1; |
| 3989 | requiredServerFilesManifest: NextRequiredServerFilesManifest; |
| 3990 | }): Promise<null | { |
| 3991 | lambdas: Record<string, NodejsLambda>; |
| 3992 | routes: RouteWithSrc[]; |
| 3993 | }> { |
| 3994 | const middlewareFunctionConfig = |
| 3995 | functionsConfigManifest?.functions['/_middleware']; |
| 3996 | |
| 3997 | if (!middlewareFunctionConfig || !middlewareFunctionConfig.matchers) { |
| 3998 | return null; |
| 3999 | } |
| 4000 | const routes: RouteWithSrc[] = []; |
| 4001 | // Pass page: '/' to skip basePath addition in getRouteMatchers(), since |
| 4002 | // functions-config-manifest matchers already have basePath baked in by |
| 4003 | // Next.js build. This matches the behavior for edge middleware where |
| 4004 | // page is '/' (root middleware) and basePath is not added. |
| 4005 | const routeMatchers = getRouteMatchers( |
| 4006 | { matchers: middlewareFunctionConfig.matchers, page: '/' }, |
| 4007 | routesManifest |
| 4008 | ); |
| 4009 | |
| 4010 | for (const matcher of routeMatchers) { |
| 4011 | const route: Route = { |
| 4012 | continue: true, |
| 4013 | src: matcher.regexp, |
| 4014 | has: matcher.has, |
| 4015 | missing: [ |
no test coverage detected