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

Function shouldServe

packages/cli/src/util/dev/server.ts:3272–3345  ·  view source on GitHub ↗
(
  match: BuildMatch,
  files: BuilderInputs,
  requestPath: string,
  devServer: DevServer,
  vercelConfig: VercelConfig,
  isFilesystem = false,
  hasMatched = false
)

Source from the content-addressed store, hash-verified

3270}
3271
3272async 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;

Callers 2

findBuildMatchFunction · 0.70

Calls 3

findAssetFunction · 0.85
shouldServeMethod · 0.80
findMatchingRouteFunction · 0.70

Tested by

no test coverage detected