( match: BuildMatch, files: BuilderInputs, requestPath: string, devServer: DevServer, vercelConfig: VercelConfig, isFilesystem = false, hasMatched = false )
| 3270 | } |
| 3271 | |
| 3272 | async function shouldServe( |
| 3273 | match: BuildMatch, |
| 3274 | files: BuilderInputs, |
| 3275 | requestPath: string, |
| 3276 | devServer: DevServer, |
| 3277 | vercelConfig: VercelConfig, |
| 3278 | isFilesystem = false, |
| 3279 | hasMatched = false |
| 3280 | ): Promise<boolean> { |
| 3281 | const { |
| 3282 | src, |
| 3283 | config, |
| 3284 | builderWithPkg: { builder }, |
| 3285 | } = match; |
| 3286 | |
| 3287 | // "middleware" file is not served as a regular asset, |
| 3288 | // instead it gets invoked as part of the routing logic. |
| 3289 | if (config?.middleware === true) { |
| 3290 | return false; |
| 3291 | } |
| 3292 | |
| 3293 | const cleanSrc = src.endsWith('.html') ? src.slice(0, -5) : src; |
| 3294 | const trimmedPath = requestPath.endsWith('/') |
| 3295 | ? requestPath.slice(0, -1) |
| 3296 | : requestPath; |
| 3297 | |
| 3298 | if ( |
| 3299 | vercelConfig.cleanUrls && |
| 3300 | vercelConfig.trailingSlash && |
| 3301 | cleanSrc === trimmedPath |
| 3302 | ) { |
| 3303 | // Mimic fmeta-util and convert cleanUrls and trailingSlash |
| 3304 | return true; |
| 3305 | } else if ( |
| 3306 | vercelConfig.cleanUrls && |
| 3307 | !vercelConfig.trailingSlash && |
| 3308 | cleanSrc === requestPath |
| 3309 | ) { |
| 3310 | // Mimic fmeta-util and convert cleanUrls |
| 3311 | return true; |
| 3312 | } else if ( |
| 3313 | !vercelConfig.cleanUrls && |
| 3314 | vercelConfig.trailingSlash && |
| 3315 | src === trimmedPath |
| 3316 | ) { |
| 3317 | // Mimic fmeta-util and convert trailingSlash |
| 3318 | return true; |
| 3319 | } else if (typeof builder.shouldServe === 'function') { |
| 3320 | const shouldServe = await builder.shouldServe({ |
| 3321 | entrypoint: src, |
| 3322 | files, |
| 3323 | config: config || {}, |
| 3324 | requestPath, |
| 3325 | workPath: devServer.cwd, |
| 3326 | hasMatched, |
| 3327 | }); |
| 3328 | if (shouldServe) { |
| 3329 | return true; |
no test coverage detected