( reqUrl: string = '/', reqMethod?: string, routes?: Route[], devServer?: DevServer, vercelConfig?: VercelConfig, previousHeaders?: HttpHeadersConfig, missRoutes?: Route[], phase?: HandleValue | null )
| 48 | } |
| 49 | |
| 50 | export 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' && |
no test coverage detected