MCPcopy
hub / github.com/vercel/next.js / handleRequest

Function handleRequest

packages/next/src/server/lib/router-server.ts:371–697  ·  view source on GitHub ↗
(handleIndex: number)

Source from the content-addressed store, hash-verified

369 }
370
371 const handleRequest = async (handleIndex: number) => {
372 if (handleIndex > 5) {
373 throw new Error(`Attempted to handle request too many times ${req.url}`)
374 }
375
376 // handle hot-reloader first
377 if (development) {
378 if (
379 blockCrossSiteDEV(
380 req,
381 res,
382 development.config.allowedDevOrigins,
383 opts.hostname
384 )
385 ) {
386 return
387 }
388
389 const origUrl = req.url || '/'
390
391 // both the basePath and assetPrefix need to be stripped from the URL
392 // so that the development bundler can find the correct file
393 if (config.basePath && pathHasPrefix(origUrl, config.basePath)) {
394 req.url = removePathPrefix(origUrl, config.basePath)
395 } else if (
396 config.assetPrefix &&
397 pathHasPrefix(origUrl, config.assetPrefix)
398 ) {
399 req.url = removePathPrefix(origUrl, config.assetPrefix)
400 }
401
402 const parsedUrl = parseUrlUtil(req.url || '/')
403
404 const hotReloaderResult = await development.bundler.hotReloader.run(
405 req,
406 res,
407 parsedUrl
408 )
409
410 if (hotReloaderResult.finished) {
411 return hotReloaderResult
412 }
413
414 req.url = origUrl
415 }
416
417 const {
418 finished,
419 parsedUrl,
420 statusCode,
421 resHeaders,
422 bodyStream,
423 matchedOutput,
424 } = await resolveRoutes({
425 req,
426 res,
427 isUpgradeReq: false,
428 signal: signalFromNodeResponse(res),

Callers 2

invokeRenderFunction · 0.70
requestHandlerImplFunction · 0.70

Calls 15

blockCrossSiteDEVFunction · 0.90
pathHasPrefixFunction · 0.90
removePathPrefixFunction · 0.90
signalFromNodeResponseFunction · 0.90
pipeToNodeResponseFunction · 0.90
proxyRequestFunction · 0.90
getRequestMetaFunction · 0.90
serveStaticFunction · 0.90
invokeRenderFunction · 0.85
isNextFontFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…