Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
1 line
No EOL
15 KiB
Text
1 line
No EOL
15 KiB
Text
{"version":3,"sources":["../../../src/export/routes/app-page.ts"],"sourcesContent":["import type { OutgoingHttpHeaders } from 'node:http'\nimport type { ExportRouteResult } from '../types'\nimport type { RenderOpts } from '../../server/app-render/types'\nimport type { NextParsedUrlQuery } from '../../server/request-meta'\nimport type { RouteMetadata } from './types'\n\nimport type {\n MockedRequest,\n MockedResponse,\n} from '../../server/lib/mock-request'\nimport { isDynamicUsageError } from '../helpers/is-dynamic-usage-error'\nimport {\n NEXT_CACHE_TAGS_HEADER,\n NEXT_META_SUFFIX,\n RSC_PREFETCH_SUFFIX,\n RSC_SUFFIX,\n RSC_SEGMENTS_DIR_SUFFIX,\n RSC_SEGMENT_SUFFIX,\n} from '../../lib/constants'\nimport { hasNextSupport } from '../../server/ci-info'\nimport { lazyRenderAppPage } from '../../server/route-modules/app-page/module.render'\nimport { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'\nimport { NodeNextRequest, NodeNextResponse } from '../../server/base-http/node'\nimport { NEXT_IS_PRERENDER_HEADER } from '../../client/components/app-router-headers'\nimport type { FetchMetrics } from '../../server/base-http'\nimport type { WorkStore } from '../../server/app-render/work-async-storage.external'\nimport type { OpaqueFallbackRouteParams } from '../../server/request/fallback-params'\nimport { AfterRunner } from '../../server/after/run-with-after'\nimport type { RequestLifecycleOpts } from '../../server/base-server'\nimport type { AppSharedContext } from '../../server/app-render/app-render'\nimport type { MultiFileWriter } from '../../lib/multi-file-writer'\nimport { stringifyResumeDataCache } from '../../server/resume-data-cache/resume-data-cache'\nimport {\n UNDERSCORE_GLOBAL_ERROR_ROUTE_ENTRY,\n UNDERSCORE_NOT_FOUND_ROUTE_ENTRY,\n} from '../../shared/lib/entry-constants'\n\n/**\n * Renders & exports a page associated with the /app directory\n */\nexport async function exportAppPage(\n req: MockedRequest,\n res: MockedResponse,\n page: string,\n path: string,\n pathname: string,\n query: NextParsedUrlQuery,\n fallbackRouteParams: OpaqueFallbackRouteParams | null,\n partialRenderOpts: Omit<RenderOpts, keyof RequestLifecycleOpts>,\n htmlFilepath: string,\n debugOutput: boolean,\n isDynamicError: boolean,\n fileWriter: MultiFileWriter,\n sharedContext: AppSharedContext\n): Promise<ExportRouteResult> {\n const afterRunner = new AfterRunner()\n\n const renderOpts: RenderOpts = {\n ...partialRenderOpts,\n waitUntil: afterRunner.context.waitUntil,\n onClose: afterRunner.context.onClose,\n onAfterTaskError: afterRunner.context.onTaskError,\n }\n\n let isDefaultNotFound = false\n let isDefaultGlobalError = false\n // If the page is `/_not-found`, then we should update the page to be `/404`.\n if (page === UNDERSCORE_NOT_FOUND_ROUTE_ENTRY) {\n isDefaultNotFound = true\n pathname = '/404'\n }\n // If the page is `/_global-error`, then we should update the page to be `/500`.\n if (page === UNDERSCORE_GLOBAL_ERROR_ROUTE_ENTRY) {\n isDefaultGlobalError = true\n pathname = '/500'\n }\n\n try {\n const result = await lazyRenderAppPage(\n new NodeNextRequest(req),\n new NodeNextResponse(res),\n pathname,\n query,\n fallbackRouteParams,\n renderOpts,\n undefined,\n sharedContext\n )\n\n const html = result.toUnchunkedString()\n\n // TODO(after): if we abort a prerender because of an error in an after-callback\n // we should probably communicate that better (and not log the error twice)\n await afterRunner.executeAfter()\n\n const { metadata } = result\n const {\n flightData,\n cacheControl = { revalidate: false, expire: undefined },\n postponed,\n fetchTags,\n fetchMetrics,\n segmentData,\n renderResumeDataCache,\n } = metadata\n\n // Ensure we don't postpone without having PPR enabled.\n if (postponed && !renderOpts.experimental.isRoutePPREnabled) {\n throw new Error('Invariant: page postponed without PPR being enabled')\n }\n\n if (cacheControl.revalidate === 0) {\n if (isDynamicError) {\n throw new Error(\n `Page with dynamic = \"error\" encountered dynamic data method on ${path}.`\n )\n }\n const { staticBailoutInfo = {} } = metadata\n\n if (debugOutput && staticBailoutInfo?.description) {\n logDynamicUsageWarning({\n path,\n description: staticBailoutInfo.description,\n stack: staticBailoutInfo.stack,\n })\n }\n\n return { cacheControl, fetchMetrics }\n }\n\n // If page data isn't available, it means that the page couldn't be rendered\n // properly so long as we don't have unknown route params. When a route doesn't\n // have unknown route params, there will not be any flight data.\n if (!flightData) {\n if (\n !fallbackRouteParams ||\n fallbackRouteParams.size === 0 ||\n renderOpts.cacheComponents\n ) {\n throw new Error(`Invariant: failed to get page data for ${path}`)\n }\n } else {\n // If PPR is enabled, we want to emit a prefetch rsc file for the page\n // instead of the standard rsc. This is because the standard rsc will\n // contain the dynamic data. We do this if any routes have PPR enabled so\n // that the cache read/write is the same.\n if (renderOpts.experimental.isRoutePPREnabled) {\n // If PPR is enabled, we should emit the flight data as the prefetch\n // payload.\n // TODO: This will eventually be replaced by the per-segment prefetch\n // output below.\n fileWriter.append(\n htmlFilepath.replace(/\\.html$/, RSC_PREFETCH_SUFFIX),\n flightData\n )\n } else {\n // Writing the RSC payload to a file if we don't have PPR enabled.\n fileWriter.append(\n htmlFilepath.replace(/\\.html$/, RSC_SUFFIX),\n flightData\n )\n }\n }\n\n let segmentPaths\n if (segmentData) {\n // Emit the per-segment prefetch data. We emit them as separate files\n // so that the cache handler has the option to treat each as a\n // separate entry.\n segmentPaths = []\n const segmentsDir = htmlFilepath.replace(\n /\\.html$/,\n RSC_SEGMENTS_DIR_SUFFIX\n )\n\n for (const [segmentPath, buffer] of segmentData) {\n segmentPaths.push(segmentPath)\n const segmentDataFilePath =\n segmentsDir + segmentPath + RSC_SEGMENT_SUFFIX\n fileWriter.append(segmentDataFilePath, buffer)\n }\n }\n\n const headers: OutgoingHttpHeaders = { ...metadata.headers }\n\n // If we're writing the file to disk, we know it's a prerender.\n headers[NEXT_IS_PRERENDER_HEADER] = '1'\n\n if (fetchTags) {\n headers[NEXT_CACHE_TAGS_HEADER] = fetchTags\n }\n\n // Writing static HTML to a file.\n fileWriter.append(htmlFilepath, html)\n\n const isParallelRoute = /\\/@\\w+/.test(page)\n const isNonSuccessfulStatusCode = res.statusCode > 300\n\n // When PPR is enabled, we don't always send 200 for routes that have been\n // pregenerated, so we should grab the status code from the mocked\n // response.\n let status: number | undefined = renderOpts.experimental.isRoutePPREnabled\n ? res.statusCode\n : undefined\n\n if (isDefaultNotFound) {\n // Override the default /_not-found page status code to 404\n status = 404\n } else if (isDefaultGlobalError) {\n // Override the default /_global-error page status code to 500\n status = 500\n } else if (isNonSuccessfulStatusCode && !isParallelRoute) {\n // If it's parallel route the status from mock response is 404\n status = res.statusCode\n }\n\n // Writing the request metadata to a file.\n const meta: RouteMetadata = {\n status,\n headers,\n postponed,\n segmentPaths,\n }\n\n fileWriter.append(\n htmlFilepath.replace(/\\.html$/, NEXT_META_SUFFIX),\n JSON.stringify(meta, null, 2)\n )\n\n return {\n // Filter the metadata if the environment does not have next support.\n metadata: hasNextSupport\n ? meta\n : {\n segmentPaths: meta.segmentPaths,\n },\n hasEmptyStaticShell: Boolean(postponed) && html === '',\n hasPostponed: Boolean(postponed),\n cacheControl,\n fetchMetrics,\n renderResumeDataCache: renderResumeDataCache\n ? await stringifyResumeDataCache(\n renderResumeDataCache,\n renderOpts.cacheComponents\n )\n : undefined,\n }\n } catch (err) {\n if (!isDynamicUsageError(err)) {\n throw err\n }\n\n // We should fail rendering if a client side rendering bailout\n // occurred at the page level.\n if (isBailoutToCSRError(err)) {\n throw err\n }\n\n let fetchMetrics: FetchMetrics | undefined\n\n if (debugOutput) {\n const store = (renderOpts as any).store as WorkStore\n const { dynamicUsageDescription, dynamicUsageStack } = store\n fetchMetrics = store.fetchMetrics\n\n logDynamicUsageWarning({\n path,\n description: dynamicUsageDescription ?? '',\n stack: dynamicUsageStack,\n })\n }\n\n return { cacheControl: { revalidate: 0, expire: undefined }, fetchMetrics }\n }\n}\n\nfunction logDynamicUsageWarning({\n path,\n description,\n stack,\n}: {\n path: string\n description: string\n stack?: string\n}) {\n const errMessage = new Error(\n `Static generation failed due to dynamic usage on ${path}, reason: ${description}`\n )\n\n if (stack) {\n errMessage.stack = errMessage.message + stack.substring(stack.indexOf('\\n'))\n }\n\n console.warn(errMessage)\n}\n"],"names":["exportAppPage","req","res","page","path","pathname","query","fallbackRouteParams","partialRenderOpts","htmlFilepath","debugOutput","isDynamicError","fileWriter","sharedContext","afterRunner","AfterRunner","renderOpts","waitUntil","context","onClose","onAfterTaskError","onTaskError","isDefaultNotFound","isDefaultGlobalError","UNDERSCORE_NOT_FOUND_ROUTE_ENTRY","UNDERSCORE_GLOBAL_ERROR_ROUTE_ENTRY","result","lazyRenderAppPage","NodeNextRequest","NodeNextResponse","undefined","html","toUnchunkedString","executeAfter","metadata","flightData","cacheControl","revalidate","expire","postponed","fetchTags","fetchMetrics","segmentData","renderResumeDataCache","experimental","isRoutePPREnabled","Error","staticBailoutInfo","description","logDynamicUsageWarning","stack","size","cacheComponents","append","replace","RSC_PREFETCH_SUFFIX","RSC_SUFFIX","segmentPaths","segmentsDir","RSC_SEGMENTS_DIR_SUFFIX","segmentPath","buffer","push","segmentDataFilePath","RSC_SEGMENT_SUFFIX","headers","NEXT_IS_PRERENDER_HEADER","NEXT_CACHE_TAGS_HEADER","isParallelRoute","test","isNonSuccessfulStatusCode","statusCode","status","meta","NEXT_META_SUFFIX","JSON","stringify","hasNextSupport","hasEmptyStaticShell","Boolean","hasPostponed","stringifyResumeDataCache","err","isDynamicUsageError","isBailoutToCSRError","store","dynamicUsageDescription","dynamicUsageStack","errMessage","message","substring","indexOf","console","warn"],"mappings":";;;;+BAwCsBA;;;eAAAA;;;qCA9Bc;2BAQ7B;wBACwB;8BACG;8BACE;sBACc;kCACT;8BAIb;iCAIa;gCAIlC;AAKA,eAAeA,cACpBC,GAAkB,EAClBC,GAAmB,EACnBC,IAAY,EACZC,IAAY,EACZC,QAAgB,EAChBC,KAAyB,EACzBC,mBAAqD,EACrDC,iBAA+D,EAC/DC,YAAoB,EACpBC,WAAo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