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

Function devRouter

packages/cli/src/util/dev/router.ts:50–293  ·  view source on GitHub ↗
(
  reqUrl: string = '/',
  reqMethod?: string,
  routes?: Route[],
  devServer?: DevServer,
  vercelConfig?: VercelConfig,
  previousHeaders?: HttpHeadersConfig,
  missRoutes?: Route[],
  phase?: HandleValue | null
)

Source from the content-addressed store, hash-verified

48}
49
50export async function devRouter(
51 reqUrl: string = '/',
52 reqMethod?: string,
53 routes?: Route[],
54 devServer?: DevServer,
55 vercelConfig?: VercelConfig,
56 previousHeaders?: HttpHeadersConfig,
57 missRoutes?: Route[],
58 phase?: HandleValue | null
59): Promise<RouteResult> {
60 let result: RouteResult | undefined;
61 let { pathname: reqPathname, search: reqSearch } = url.parse(reqUrl);
62 reqPathname = reqPathname || '/';
63 const reqQuery = parseQueryString(reqSearch);
64 const combinedHeaders: HttpHeadersConfig = { ...previousHeaders };
65 let status: number | undefined;
66 let isContinue = false;
67
68 const requestTransforms: Transform[] = [];
69 let responseTransforms: Transform[] | undefined;
70
71 // Try route match
72 if (routes) {
73 let idx = -1;
74 for (const routeConfig of routes) {
75 idx++;
76 isContinue = false;
77
78 if (isHandler(routeConfig)) {
79 // We don't expect any Handle, only Source routes
80 continue;
81 }
82
83 const { src, headers, methods } = routeConfig;
84
85 if (Array.isArray(methods) && reqMethod && !methods.includes(reqMethod)) {
86 continue;
87 }
88
89 const keys: string[] = [];
90 const flags = devServer && devServer.isCaseSensitive() ? '' : 'i';
91 const matcher = PCRE(`%${src}%${flags}`, keys);
92 const match =
93 matcher.exec(reqPathname) || matcher.exec(reqPathname.substring(1));
94
95 if (match) {
96 const routeTransforms = routeConfig.transforms
97 ? resolveTransforms(routeConfig.transforms, {
98 match,
99 keys,
100 env: devServer?.envConfigs.runEnv,
101 })
102 : [];
103
104 // A `service` destination is a terminal marker-only handoff, no
105 // transforms will be applied for this route
106 const isServiceMarker =
107 typeof routeConfig.destination === 'object' &&

Callers 5

router.test.tsFile · 0.90
_startMethod · 0.90
delegateToServiceMethod · 0.90
DevServerClass · 0.90
findMatchingRouteFunction · 0.90

Calls 10

parseQueryStringFunction · 0.90
isHandlerFunction · 0.90
resolveTransformsFunction · 0.90
resolveRouteParametersFunction · 0.85
isURLFunction · 0.85
isCaseSensitiveMethod · 0.80
hasFilesystemMethod · 0.80
pushMethod · 0.65
parseMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected