MCPcopy Create free account
hub / github.com/dailydotdev/apps / getLayoutVariantResponse

Function getLayoutVariantResponse

packages/webapp/proxy.ts:133–159  ·  view source on GitHub ↗
(
  req: NextRequest,
)

Source from the content-addressed store, hash-verified

131// Only the post page is mirrored — every mirrored route doubles its ISR
132// entries and its revalidation traffic.
133export const getLayoutVariantResponse = (
134 req: NextRequest,
135): NextResponse | undefined => {
136 const { pathname } = req.nextUrl;
137
138 // Next normalises `/_next/data/<buildId>/posts/x.json` down to the page
139 // path, so a soft navigation reaches here looking exactly like a document
140 // request. Rewriting it answers with the mirror's route, which moves the
141 // client onto a route it never asked for; the shell is already resolved by
142 // then, so only the initial document needs the mirror.
143 if (
144 req.headers.has('x-nextjs-data') ||
145 req.cookies.get(LAYOUT_VARIANT_COOKIE)?.value !== 'v2' ||
146 !isPostPermalinkPath(pathname)
147 ) {
148 return undefined;
149 }
150
151 const url = req.nextUrl.clone();
152 url.pathname = `${LAYOUT_VARIANT_ROUTE_PREFIX}${pathname}`;
153
154 // Names the shell the response was built with, so the mirror can be told
155 // apart from the plain page in logs and when debugging a cached page.
156 return NextResponse.rewrite(url, {
157 headers: { 'x-layout-variant': 'v2' },
158 });
159};
160
161export async function proxy(req: NextRequest): Promise<NextResponse> {
162 if (isMarkdownRequest(req)) {

Callers 2

rewrittenToFunction · 0.90
proxyFunction · 0.85

Calls 1

isPostPermalinkPathFunction · 0.90

Tested by 1

rewrittenToFunction · 0.72