MCPcopy Create free account
hub / github.com/vercel/vercel / getMiddlewareBundle

Function getMiddlewareBundle

packages/next/src/utils.ts:4144–4391  ·  view source on GitHub ↗
({
  entryPath,
  outputDirectory,
  routesManifest,
  isCorrectMiddlewareOrder,
  prerenderBypassToken,
  nextVersion,
  appPathRoutesManifest,
}: {
  config: Config;
  entryPath: string;
  outputDirectory: string;
  prerenderBypassToken: string;
  routesManifest: RoutesManifest;
  isCorrectMiddlewareOrder: boolean;
  nextVersion: string;
  appPathRoutesManifest: Record<string, string>;
})

Source from the content-addressed store, hash-verified

4142}
4143
4144export async function getMiddlewareBundle({
4145 entryPath,
4146 outputDirectory,
4147 routesManifest,
4148 isCorrectMiddlewareOrder,
4149 prerenderBypassToken,
4150 nextVersion,
4151 appPathRoutesManifest,
4152}: {
4153 config: Config;
4154 entryPath: string;
4155 outputDirectory: string;
4156 prerenderBypassToken: string;
4157 routesManifest: RoutesManifest;
4158 isCorrectMiddlewareOrder: boolean;
4159 nextVersion: string;
4160 appPathRoutesManifest: Record<string, string>;
4161}): Promise<{
4162 staticRoutes: Route[];
4163 dynamicRouteMap: ReadonlyMap<string, RouteWithSrc>;
4164 edgeFunctions: Record<string, EdgeFunction>;
4165}> {
4166 const middlewareManifest = await getMiddlewareManifest(
4167 entryPath,
4168 outputDirectory
4169 );
4170 const sortedFunctions = [
4171 ...(!middlewareManifest
4172 ? []
4173 : middlewareManifest.sortedMiddleware.map(key => ({
4174 key,
4175 edgeFunction: middlewareManifest?.middleware[key],
4176 type: 'middleware' as const,
4177 }))),
4178
4179 ...Object.entries(middlewareManifest?.functions ?? {}).map(
4180 ([key, edgeFunction]) => {
4181 return {
4182 key,
4183 edgeFunction,
4184 type: 'function' as const,
4185 };
4186 }
4187 ),
4188 ];
4189
4190 if (middlewareManifest && sortedFunctions.length > 0) {
4191 const workerConfigs = await Promise.all(
4192 sortedFunctions.map(async ({ key, edgeFunction, type }) => {
4193 try {
4194 const wrappedModuleSource = await getNextjsEdgeFunctionSource(
4195 edgeFunction.files,
4196 {
4197 name: edgeFunction.name,
4198 staticRoutes: routesManifest.staticRoutes,
4199 dynamicRoutes: routesManifest.dynamicRoutes.filter(
4200 r => !('isMiddleware' in r)
4201 ),

Callers 2

getMiddlewareRoutesFunction · 0.90
serverBuildFunction · 0.90

Calls 15

stringifySourceMapFunction · 0.90
isDynamicRouteFunction · 0.90
getMiddlewareManifestFunction · 0.85
transformSourceMapFunction · 0.85
normalizeRegionsFunction · 0.85
getRouteMatchersFunction · 0.85
normalizeIndexOutputFunction · 0.85
filterMethod · 0.80
replaceMethod · 0.80
pushMethod · 0.65

Tested by 1

getMiddlewareRoutesFunction · 0.72