Unverified Commit f3222471 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update cache method handling during build (#49633)

This ensures we properly handle fetch cache during build.
parent ce746ef5
......@@ -63,6 +63,7 @@ import { IncrementalCache } from '../server/lib/incremental-cache'
import { patchFetch } from '../server/lib/patch-fetch'
import { nodeFs } from '../server/lib/node-fs-methods'
import '../server/node-environment'
import * as ciEnvironment from '../telemetry/ci-info'
export type ROUTER_TYPE = 'pages' | 'app'
......@@ -1216,6 +1217,7 @@ export async function buildAppStaticPaths({
}),
CurCacheHandler: CacheHandler,
requestHeaders,
minimalMode: ciEnvironment.hasNextSupport,
})
return StaticGenerationAsyncStorageWrapper.wrap(
......
......@@ -371,6 +371,7 @@ export default async function exportPage({
},
serverDistDir: join(distDir, 'server'),
CurCacheHandler: CacheHandler,
minimalMode: ciEnvironment.hasNextSupport,
})
;(globalThis as any).__incrementalCache = incrementalCache
curRenderOpts.incrementalCache = incrementalCache
......
......@@ -34,10 +34,21 @@ export default class FetchCache implements CacheHandler {
}
delete ctx._requestHeaders[FETCH_CACHE_HEADER]
}
if (ctx._requestHeaders['x-vercel-sc-host']) {
this.cacheEndpoint = `https://${ctx._requestHeaders['x-vercel-sc-host']}${
ctx._requestHeaders['x-vercel-sc-basepath'] || ''
}`
const scHost =
ctx._requestHeaders['x-vercel-sc-host'] || process.env.SUSPENSE_CACHE_URL
const scBasePath =
ctx._requestHeaders['x-vercel-sc-basepath'] ||
process.env.SUSPENSE_CACHE_BASEPATH
if (process.env.SUSPENSE_CACHE_AUTH_TOKEN) {
this.headers[
'Authorization'
] = `Bearer ${process.env.SUSPENSE_CACHE_AUTH_TOKEN}`
}
if (scHost) {
this.cacheEndpoint = `https://${scHost}${scBasePath || ''}`
if (this.debug) {
console.log('using cache endpoint', this.cacheEndpoint)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment