Skip to content

Commit 9a52755

Browse files
committed
fix: static html blobs if distDir is different than default .next
1 parent bc6dc50 commit 9a52755

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/run/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const getRunConfig = async () => {
1919
return JSON.parse(await readFile(resolve(PLUGIN_DIR, RUN_CONFIG_FILE), 'utf-8')) as RunConfig
2020
}
2121

22-
type NextConfigForMultipleVersions = NextConfigComplete & {
22+
export type NextConfigForMultipleVersions = NextConfigComplete & {
2323
experimental: NextConfigComplete['experimental'] & {
2424
// those are pre 14.1.0 options that were moved out of experimental in // https://github.com/vercel/next.js/pull/57953/files#diff-c49c4767e6ed8627e6e1b8f96b141ee13246153f5e9142e1da03450c8e81e96fL311
2525

@@ -62,4 +62,6 @@ export const setRunConfig = (config: NextConfigForMultipleVersions) => {
6262

6363
// set config
6464
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config)
65+
66+
return config
6567
}

src/run/handlers/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import { setupWaitUntil } from './wait-until.cjs'
2424
setFetchBeforeNextPatchedIt(globalThis.fetch)
2525
// configure globals that Next.js make use of before we start importing any Next.js code
2626
// as some globals are consumed at import time
27-
const { nextConfig, enableUseCacheHandler } = await getRunConfig()
27+
const { nextConfig: initialNextConfig, enableUseCacheHandler } = await getRunConfig()
2828
if (enableUseCacheHandler) {
2929
configureUseCacheHandlers()
3030
}
31-
setRunConfig(nextConfig)
31+
const nextConfig = setRunConfig(initialNextConfig)
3232
setupWaitUntil()
3333

3434
const nextImportPromise = import('../next.cjs')
@@ -71,7 +71,7 @@ export default async (
7171
const { getMockedRequestHandler } = await nextImportPromise
7272
const url = new URL(request.url)
7373

74-
nextHandler = await getMockedRequestHandler({
74+
nextHandler = await getMockedRequestHandler(nextConfig, {
7575
port: Number(url.port) || 443,
7676
hostname: url.hostname,
7777
dir: process.cwd(),

src/run/next.cts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { AsyncLocalStorage } from 'node:async_hooks'
22
import fs from 'node:fs/promises'
3-
import { relative, resolve } from 'node:path'
3+
import { relative, resolve, join } from 'node:path'
44

55
// @ts-expect-error no types installed
66
import { patchFs } from 'fs-monkey'
77

88
import { HtmlBlob } from '../shared/blob-types.cjs'
99

10+
import type { NextConfigForMultipleVersions } from './config.js'
1011
import { getRequestContext } from './handlers/request-context.cjs'
1112
import { getTracer } from './handlers/tracer.cjs'
1213
import { getMemoizedKeyValueStoreBackedByRegionalBlobStore } from './storage/storage.cjs'
@@ -79,7 +80,10 @@ ResponseCache.prototype.get = function get(...getArgs: unknown[]) {
7980

8081
type FS = typeof import('fs')
8182

82-
export async function getMockedRequestHandler(...args: Parameters<typeof getRequestHandlers>) {
83+
export async function getMockedRequestHandler(
84+
nextConfig: NextConfigForMultipleVersions,
85+
...args: Parameters<typeof getRequestHandlers>
86+
) {
8387
const initContext = { initializingServer: true }
8488
/**
8589
* Using async local storage to identify operations happening as part of server initialization
@@ -101,8 +105,9 @@ export async function getMockedRequestHandler(...args: Parameters<typeof getRequ
101105
// only try to get .html files from the blob store
102106
if (typeof path === 'string' && path.endsWith('.html')) {
103107
const cacheStore = getMemoizedKeyValueStoreBackedByRegionalBlobStore()
104-
const relPath = relative(resolve('.next/server/pages'), path)
108+
const relPath = relative(resolve(nextConfig.distDir, 'server/pages'), path)
105109
const file = await cacheStore.get<HtmlBlob>(relPath, 'staticHtml.get')
110+
console.log('trying to read path', { path, relPath, file })
106111
if (file !== null) {
107112
if (file.isFullyStaticPage) {
108113
const requestContext = getRequestContext()

0 commit comments

Comments
 (0)