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

Function denormalizeNextDataUrl

packages/next-routing/src/next-data.ts:36–59  ·  view source on GitHub ↗
(
  url: URL,
  basePath: string,
  buildId: string
)

Source from the content-addressed store, hash-verified

34 * ${basePath}/$path -> ${basePath}/_next/data/$buildId/$path.json
35 */
36export function denormalizeNextDataUrl(
37 url: URL,
38 basePath: string,
39 buildId: string
40): URL {
41 const newUrl = new URL(url.toString())
42 let pathname = newUrl.pathname
43
44 // Only denormalize if it's not already a data URL
45 const dataPrefix = `${basePath}/_next/data/${buildId}/`
46 if (!pathname.startsWith(dataPrefix)) {
47 // Remove basePath if present
48 let pathWithoutBase = pathname
49 if (basePath && pathname.startsWith(basePath)) {
50 pathWithoutBase = pathname.slice(basePath.length)
51 }
52
53 // Add the /_next/data/${buildId}/ prefix and .json extension
54 pathname = `${basePath}/_next/data/${buildId}${pathWithoutBase}.json`
55 newUrl.pathname = pathname
56 }
57
58 return newUrl
59}

Callers 2

checkDynamicRoutesFunction · 0.90
resolveRoutesFunction · 0.90

Calls 3

startsWithMethod · 0.80
toStringMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…