Restore UI functionalities and clean up dependencies

This commit is contained in:
streaper2
2026-05-08 08:32:58 +02:00
parent 8946955f76
commit 0895b7d5bc
26751 changed files with 4207476 additions and 158 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,365 @@
import { AppRouteRouteModule } from '../../server/route-modules/app-route/module.compiled';
import { RouteKind } from '../../server/route-kind';
import { patchFetch as _patchFetch } from '../../server/lib/patch-fetch';
import { addRequestMeta, getRequestMeta, setRequestMeta } from '../../server/request-meta';
import { getTracer, SpanKind } from '../../server/lib/trace/tracer';
import { setManifestsSingleton } from '../../server/app-render/manifests-singleton';
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths';
import { NodeNextRequest, NodeNextResponse } from '../../server/base-http/node';
import { NextRequestAdapter, signalFromNodeResponse } from '../../server/web/spec-extension/adapters/next-request';
import { BaseServerSpan } from '../../server/lib/trace/constants';
import { getRevalidateReason } from '../../server/instrumentation/utils';
import { sendResponse } from '../../server/send-response';
import { fromNodeOutgoingHttpHeaders, toNodeOutgoingHttpHeaders } from '../../server/web/utils';
import { getCacheControlHeader } from '../../server/lib/cache-control';
import { INFINITE_CACHE, NEXT_CACHE_TAGS_HEADER } from '../../lib/constants';
import { NoFallbackError } from '../../shared/lib/no-fallback-error.external';
import { CachedRouteKind } from '../../server/response-cache';
import * as userland from 'VAR_USERLAND';
// We inject the nextConfigOutput here so that we can use them in the route
// module.
// INJECT:nextConfigOutput
const routeModule = new AppRouteRouteModule({
definition: {
kind: RouteKind.APP_ROUTE,
page: 'VAR_DEFINITION_PAGE',
pathname: 'VAR_DEFINITION_PATHNAME',
filename: 'VAR_DEFINITION_FILENAME',
bundlePath: 'VAR_DEFINITION_BUNDLE_PATH'
},
distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',
relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || '',
resolvedPagePath: 'VAR_RESOLVED_PAGE_PATH',
nextConfigOutput,
// The static import is used for initialization (methods, dynamic, etc.).
userland: userland,
// In Turbopack dev mode, also provide a getter that calls require() on every
// request. This re-reads from devModuleCache so HMR updates are picked up,
// and the async wrapper unwraps async-module Promises (ESM-only
// serverExternalPackages) automatically.
...process.env.TURBOPACK && process.env.__NEXT_DEV_SERVER ? {
getUserland: ()=>import('VAR_USERLAND')
} : {}
});
// Pull out the exports that we need to expose from the module. This should
// be eliminated when we've moved the other routes to the new format. These
// are used to hook into the route.
const { workAsyncStorage, workUnitAsyncStorage, serverHooks } = routeModule;
function patchFetch() {
return _patchFetch({
workAsyncStorage,
workUnitAsyncStorage
});
}
export { routeModule, workAsyncStorage, workUnitAsyncStorage, serverHooks, patchFetch, };
export async function handler(req, res, ctx) {
if (ctx.requestMeta) {
setRequestMeta(req, ctx.requestMeta);
}
if (routeModule.isDev) {
addRequestMeta(req, 'devRequestTimingInternalsEnd', process.hrtime.bigint());
}
let srcPage = 'VAR_DEFINITION_PAGE';
// turbopack doesn't normalize `/index` in the page name
// so we need to to process dynamic routes properly
// TODO: fix turbopack providing differing value from webpack
if (process.env.TURBOPACK) {
srcPage = srcPage.replace(/\/index$/, '') || '/';
} else if (srcPage === '/index') {
// we always normalize /index specifically
srcPage = '/';
}
const multiZoneDraftMode = process.env.__NEXT_MULTI_ZONE_DRAFT_MODE;
const prepareResult = await routeModule.prepare(req, res, {
srcPage,
multiZoneDraftMode
});
if (!prepareResult) {
res.statusCode = 400;
res.end('Bad Request');
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, Promise.resolve());
return null;
}
const { buildId, params, nextConfig, parsedUrl, isDraftMode, prerenderManifest, routerServerContext, isOnDemandRevalidate, revalidateOnlyGenerated, resolvedPathname, clientReferenceManifest, serverActionsManifest } = prepareResult;
const normalizedSrcPage = normalizeAppPath(srcPage);
let isIsr = Boolean(prerenderManifest.dynamicRoutes[normalizedSrcPage] || prerenderManifest.routes[resolvedPathname]);
const render404 = async ()=>{
// TODO: should route-module itself handle rendering the 404
if (routerServerContext == null ? void 0 : routerServerContext.render404) {
await routerServerContext.render404(req, res, parsedUrl, false);
} else {
res.end('This page could not be found');
}
return null;
};
if (isIsr && !isDraftMode) {
const isPrerendered = Boolean(prerenderManifest.routes[resolvedPathname]);
const prerenderInfo = prerenderManifest.dynamicRoutes[normalizedSrcPage];
if (prerenderInfo) {
if (prerenderInfo.fallback === false && !isPrerendered) {
if (nextConfig.adapterPath) {
return await render404();
}
throw new NoFallbackError();
}
}
}
let cacheKey = null;
if (isIsr && !routeModule.isDev && !isDraftMode) {
cacheKey = resolvedPathname;
// ensure /index and / is normalized to one key
cacheKey = cacheKey === '/index' ? '/' : cacheKey;
}
const supportsDynamicResponse = // If we're in development, we always support dynamic HTML
routeModule.isDev === true || // If this is not SSG or does not have static paths, then it supports
// dynamic HTML.
!isIsr;
// This is a revalidation request if the request is for a static
// page and it is not being resumed from a postponed render and
// it is not a dynamic RSC request then it is a revalidation
// request.
const isStaticGeneration = isIsr && !supportsDynamicResponse;
// Before rendering (which initializes component tree modules), we have to
// set the reference manifests to our global store so Server Action's
// encryption util can access to them at the top level of the page module.
if (serverActionsManifest && clientReferenceManifest) {
setManifestsSingleton({
page: srcPage,
clientReferenceManifest,
serverActionsManifest
});
}
const method = req.method || 'GET';
const tracer = getTracer();
const activeSpan = tracer.getActiveScopeSpan();
const isWrappedByNextServer = Boolean(routerServerContext == null ? void 0 : routerServerContext.isWrappedByNextServer);
const isMinimalMode = Boolean(getRequestMeta(req, 'minimalMode'));
const incrementalCache = getRequestMeta(req, 'incrementalCache') || await routeModule.getIncrementalCache(req, nextConfig, prerenderManifest, isMinimalMode);
incrementalCache == null ? void 0 : incrementalCache.resetRequestCache();
globalThis.__incrementalCache = incrementalCache;
const context = {
params,
previewProps: prerenderManifest.preview,
renderOpts: {
experimental: {
authInterrupts: Boolean(nextConfig.experimental.authInterrupts)
},
cacheComponents: Boolean(nextConfig.cacheComponents),
supportsDynamicResponse,
incrementalCache,
cacheLifeProfiles: nextConfig.cacheLife,
waitUntil: ctx.waitUntil,
onClose: (cb)=>{
res.on('close', cb);
},
onAfterTaskError: undefined,
onInstrumentationRequestError: (error, _request, errorContext, silenceLog)=>routeModule.onRequestError(req, error, errorContext, silenceLog, routerServerContext)
},
sharedContext: {
buildId
}
};
const nodeNextReq = new NodeNextRequest(req);
const nodeNextRes = new NodeNextResponse(res);
const nextReq = NextRequestAdapter.fromNodeNextRequest(nodeNextReq, signalFromNodeResponse(res));
try {
let parentSpan;
const invokeRouteModule = async (span)=>{
return routeModule.handle(nextReq, context).finally(()=>{
if (!span) return;
span.setAttributes({
'http.status_code': res.statusCode,
'next.rsc': false
});
const rootSpanAttributes = tracer.getRootSpanAttributes();
// We were unable to get attributes, probably OTEL is not enabled
if (!rootSpanAttributes) {
return;
}
if (rootSpanAttributes.get('next.span_type') !== BaseServerSpan.handleRequest) {
console.warn(`Unexpected root span type '${rootSpanAttributes.get('next.span_type')}'. Please report this Next.js issue https://github.com/vercel/next.js`);
return;
}
const route = rootSpanAttributes.get('next.route');
if (route) {
const name = `${method} ${route}`;
span.setAttributes({
'next.route': route,
'http.route': route,
'next.span_name': name
});
span.updateName(name);
// Propagate http.route to the parent span if one exists (e.g.
// a platform-created HTTP span in adapter deployments).
if (parentSpan && parentSpan !== span) {
parentSpan.setAttribute('http.route', route);
parentSpan.updateName(name);
}
} else {
span.updateName(`${method} ${srcPage}`);
}
});
};
const handleResponse = async (currentSpan)=>{
var _cacheEntry_value;
const responseGenerator = async ({ previousCacheEntry })=>{
try {
if (!isMinimalMode && isOnDemandRevalidate && revalidateOnlyGenerated && !previousCacheEntry) {
res.statusCode = 404;
// on-demand revalidate always sets this header
res.setHeader('x-nextjs-cache', 'REVALIDATED');
res.end('This page could not be found');
return null;
}
const response = await invokeRouteModule(currentSpan);
req.fetchMetrics = context.renderOpts.fetchMetrics;
let pendingWaitUntil = context.renderOpts.pendingWaitUntil;
// Attempt using provided waitUntil if available
// if it's not we fallback to sendResponse's handling
if (pendingWaitUntil) {
if (ctx.waitUntil) {
ctx.waitUntil(pendingWaitUntil);
pendingWaitUntil = undefined;
}
}
const cacheTags = context.renderOpts.collectedTags;
// If the request is for a static response, we can cache it so long
// as it's not edge.
if (isIsr) {
const blob = await response.blob();
// Copy the headers from the response.
const headers = toNodeOutgoingHttpHeaders(response.headers);
if (cacheTags) {
headers[NEXT_CACHE_TAGS_HEADER] = cacheTags;
}
if (!headers['content-type'] && blob.type) {
headers['content-type'] = blob.type;
}
const revalidate = typeof context.renderOpts.collectedRevalidate === 'undefined' || context.renderOpts.collectedRevalidate >= INFINITE_CACHE ? false : context.renderOpts.collectedRevalidate;
const expire = typeof context.renderOpts.collectedExpire === 'undefined' || context.renderOpts.collectedExpire >= INFINITE_CACHE ? undefined : context.renderOpts.collectedExpire;
// Create the cache entry for the response.
const cacheEntry = {
value: {
kind: CachedRouteKind.APP_ROUTE,
status: response.status,
body: Buffer.from(await blob.arrayBuffer()),
headers
},
cacheControl: {
revalidate,
expire
}
};
return cacheEntry;
} else {
// send response without caching if not ISR
await sendResponse(nodeNextReq, nodeNextRes, response, context.renderOpts.pendingWaitUntil);
return null;
}
} catch (err) {
// if this is a background revalidate we need to report
// the request error here as it won't be bubbled
if (previousCacheEntry == null ? void 0 : previousCacheEntry.isStale) {
const silenceLog = false;
await routeModule.onRequestError(req, err, {
routerKind: 'App Router',
routePath: srcPage,
routeType: 'route',
revalidateReason: getRevalidateReason({
isStaticGeneration,
isOnDemandRevalidate
})
}, silenceLog, routerServerContext);
}
throw err;
}
};
const cacheEntry = await routeModule.handleResponse({
req,
nextConfig,
cacheKey,
routeKind: RouteKind.APP_ROUTE,
isFallback: false,
prerenderManifest,
isRoutePPREnabled: false,
isOnDemandRevalidate,
revalidateOnlyGenerated,
responseGenerator,
waitUntil: ctx.waitUntil,
isMinimalMode
});
// we don't create a cacheEntry for ISR
if (!isIsr) {
return null;
}
if ((cacheEntry == null ? void 0 : (_cacheEntry_value = cacheEntry.value) == null ? void 0 : _cacheEntry_value.kind) !== CachedRouteKind.APP_ROUTE) {
var _cacheEntry_value1;
throw Object.defineProperty(new Error(`Invariant: app-route received invalid cache entry ${cacheEntry == null ? void 0 : (_cacheEntry_value1 = cacheEntry.value) == null ? void 0 : _cacheEntry_value1.kind}`), "__NEXT_ERROR_CODE", {
value: "E701",
enumerable: false,
configurable: true
});
}
if (!isMinimalMode) {
res.setHeader('x-nextjs-cache', isOnDemandRevalidate ? 'REVALIDATED' : cacheEntry.isMiss ? 'MISS' : cacheEntry.isStale ? 'STALE' : 'HIT');
}
// Draft mode should never be cached
if (isDraftMode) {
res.setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate');
}
const headers = fromNodeOutgoingHttpHeaders(cacheEntry.value.headers);
if (!(isMinimalMode && isIsr)) {
headers.delete(NEXT_CACHE_TAGS_HEADER);
}
// If cache control is already set on the response we don't
// override it to allow users to customize it via next.config
if (cacheEntry.cacheControl && !res.getHeader('Cache-Control') && !headers.get('Cache-Control')) {
headers.set('Cache-Control', getCacheControlHeader(cacheEntry.cacheControl));
}
await sendResponse(nodeNextReq, nodeNextRes, // @ts-expect-error - Argument of type 'Buffer<ArrayBufferLike>' is not assignable to parameter of type 'BodyInit | null | undefined'.
new Response(cacheEntry.value.body, {
headers,
status: cacheEntry.value.status || 200
}));
return null;
};
// TODO: activeSpan code path is for when wrapped by
// next-server can be removed when this is no longer used
if (isWrappedByNextServer && activeSpan) {
await handleResponse(activeSpan);
} else {
parentSpan = tracer.getActiveScopeSpan();
await tracer.withPropagatedContext(req.headers, ()=>tracer.trace(BaseServerSpan.handleRequest, {
spanName: `${method} ${srcPage}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': method,
'http.target': req.url
}
}, handleResponse), undefined, !isWrappedByNextServer);
}
} catch (err) {
if (!(err instanceof NoFallbackError)) {
const silenceLog = false;
await routeModule.onRequestError(req, err, {
routerKind: 'App Router',
routePath: normalizedSrcPage,
routeType: 'route',
revalidateReason: getRevalidateReason({
isStaticGeneration,
isOnDemandRevalidate
})
}, silenceLog, routerServerContext);
}
// rethrow so that we can handle serving error page
// If this is during static generation, throw the error again.
if (isIsr) throw err;
// Otherwise, send a 500 response.
await sendResponse(nodeNextReq, nodeNextRes, new Response(null, {
status: 500
}));
return null;
}
}
//# sourceMappingURL=app-route.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,58 @@
var _self___RSC_MANIFEST;
import { setManifestsSingleton } from '../../server/app-render/manifests-singleton';
import { EdgeRouteModuleWrapper } from '../../server/web/edge-route-module-wrapper';
// Import the userland code.
import * as module from 'VAR_USERLAND';
import { toNodeOutgoingHttpHeaders } from '../../server/web/utils';
// OPTIONAL_IMPORT:incrementalCacheHandler
// INJECT_RAW:cacheHandlerImports
const maybeJSONParse = (str)=>str ? JSON.parse(str) : undefined;
const rscManifest = (_self___RSC_MANIFEST = self.__RSC_MANIFEST) == null ? void 0 : _self___RSC_MANIFEST['VAR_PAGE'];
const rscServerManifest = maybeJSONParse(self.__RSC_SERVER_MANIFEST);
if (rscManifest && rscServerManifest) {
setManifestsSingleton({
page: 'VAR_PAGE',
clientReferenceManifest: rscManifest,
serverActionsManifest: rscServerManifest
});
}
export const ComponentMod = module;
const edgeCacheHandlers = {};
// INJECT_RAW:edgeCacheHandlersRegistration
const internalHandler = EdgeRouteModuleWrapper.wrap(module.routeModule, {
page: 'VAR_PAGE',
cacheHandlers: edgeCacheHandlers,
incrementalCacheHandler
});
export async function handler(request, ctx) {
const result = await internalHandler({
request: {
url: request.url,
method: request.method,
headers: toNodeOutgoingHttpHeaders(request.headers),
nextConfig: {
basePath: process.env.__NEXT_BASE_PATH,
i18n: process.env.__NEXT_I18N_CONFIG,
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE,
authInterrupts: Boolean(process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS),
clientParamParsingOrigins: process.env.__NEXT_CLIENT_PARAM_PARSING_ORIGINS
}
},
page: {
name: 'VAR_PAGE'
},
body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body ?? undefined : undefined,
waitUntil: ctx.waitUntil,
requestMeta: ctx.requestMeta,
signal: ctx.signal || new AbortController().signal
}
});
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, result.waitUntil);
return result.response;
}
// backwards compat
export default internalHandler;
//# sourceMappingURL=edge-app-route.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,284 @@
var _self___RSC_MANIFEST;
import '../../server/web/globals';
import { adapter } from '../../server/web/adapter';
import { IncrementalCache } from '../../server/lib/incremental-cache';
import * as pageMod from 'VAR_USERLAND';
import { setManifestsSingleton } from '../../server/app-render/manifests-singleton';
import * as cacheHandlers from '../../server/use-cache/handlers';
import { BaseServerSpan } from '../../server/lib/trace/constants';
import { getTracer, SpanKind } from '../../server/lib/trace/tracer';
import { WebNextRequest, WebNextResponse } from '../../server/base-http/web';
import { getIsPossibleServerAction } from '../../server/lib/server-action-request-meta';
import { getBotType } from '../../shared/lib/router/utils/is-bot';
import { interopDefault } from '../../lib/interop-default';
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths';
import { checkIsOnDemandRevalidate } from '../../server/api-utils';
import { CloseController } from '../../server/web/web-on-close';
import { parseMaxPostponedStateSize } from '../../shared/lib/size-limit';
import { toNodeOutgoingHttpHeaders } from '../../server/web/utils';
// OPTIONAL_IMPORT:incrementalCacheHandler
// INJECT_RAW:cacheHandlerImports
const maybeJSONParse = (str)=>str ? JSON.parse(str) : undefined;
const rscManifest = (_self___RSC_MANIFEST = self.__RSC_MANIFEST) == null ? void 0 : _self___RSC_MANIFEST['VAR_PAGE'];
const rscServerManifest = maybeJSONParse(self.__RSC_SERVER_MANIFEST);
if (rscManifest && rscServerManifest) {
setManifestsSingleton({
page: 'VAR_PAGE',
clientReferenceManifest: rscManifest,
serverActionsManifest: rscServerManifest
});
}
export const ComponentMod = pageMod;
async function requestHandler(req, event) {
let srcPage = 'VAR_PAGE';
const normalizedSrcPage = normalizeAppPath(srcPage);
const relativeUrl = `${req.nextUrl.pathname}${req.nextUrl.search}`;
const baseReq = new WebNextRequest(req);
const baseRes = new WebNextResponse(undefined);
const pageRouteModule = pageMod.routeModule;
const prepareResult = await pageRouteModule.prepare(baseReq, null, {
srcPage,
multiZoneDraftMode: false
});
if (!prepareResult) {
return new Response('Bad Request', {
status: 400
});
}
const { query, params, buildId, nextConfig, buildManifest, prerenderManifest, reactLoadableManifest, subresourceIntegrityManifest, dynamicCssManifest, nextFontManifest, resolvedPathname, interceptionRoutePatterns, routerServerContext, deploymentId, clientAssetToken } = prepareResult;
// Initialize the cache handlers interface.
cacheHandlers.initializeCacheHandlers(nextConfig.cacheMaxMemorySize);
// INJECT_RAW:cacheHandlerRegistration
const isPossibleServerAction = getIsPossibleServerAction(req);
const botType = getBotType(req.headers.get('User-Agent') || '');
const { isOnDemandRevalidate } = checkIsOnDemandRevalidate(req, prerenderManifest.preview);
const closeController = new CloseController();
const renderContext = {
page: normalizedSrcPage,
query,
params,
sharedContext: {
buildId,
deploymentId,
clientAssetToken
},
fallbackRouteParams: null,
renderOpts: {
App: ()=>null,
Document: ()=>null,
pageConfig: {},
ComponentMod,
Component: interopDefault(ComponentMod),
routeModule: pageRouteModule,
params,
page: srcPage,
postponed: undefined,
shouldWaitOnAllReady: false,
serveStreamingMetadata: true,
supportsDynamicResponse: true,
buildManifest,
nextFontManifest,
reactLoadableManifest,
subresourceIntegrityManifest,
dynamicCssManifest,
setIsrStatus: routerServerContext == null ? void 0 : routerServerContext.setIsrStatus,
dir: pageRouteModule.relativeProjectDir,
botType,
isDraftMode: false,
isOnDemandRevalidate,
isPossibleServerAction,
assetPrefix: nextConfig.assetPrefix,
nextConfigOutput: nextConfig.output,
crossOrigin: nextConfig.crossOrigin,
trailingSlash: nextConfig.trailingSlash,
images: nextConfig.images,
previewProps: prerenderManifest.preview,
enableTainting: nextConfig.experimental.taint,
htmlLimitedBots: nextConfig.htmlLimitedBots,
reactMaxHeadersLength: nextConfig.reactMaxHeadersLength,
multiZoneDraftMode: false,
cacheLifeProfiles: nextConfig.cacheLife,
basePath: nextConfig.basePath,
serverActions: nextConfig.experimental.serverActions,
logServerFunctions: typeof nextConfig.logging === 'object' && Boolean(nextConfig.logging.serverFunctions),
cacheComponents: Boolean(nextConfig.cacheComponents),
experimental: {
isRoutePPREnabled: false,
expireTime: nextConfig.expireTime,
staleTimes: nextConfig.experimental.staleTimes,
dynamicOnHover: Boolean(nextConfig.experimental.dynamicOnHover),
optimisticRouting: Boolean(nextConfig.experimental.optimisticRouting),
inlineCss: Boolean(nextConfig.experimental.inlineCss),
prefetchInlining: nextConfig.experimental.prefetchInlining ?? false,
authInterrupts: Boolean(nextConfig.experimental.authInterrupts),
cachedNavigations: Boolean(nextConfig.experimental.cachedNavigations),
clientTraceMetadata: nextConfig.experimental.clientTraceMetadata || [],
clientParamParsingOrigins: nextConfig.experimental.clientParamParsingOrigins,
maxPostponedStateSizeBytes: parseMaxPostponedStateSize(nextConfig.experimental.maxPostponedStateSize)
},
incrementalCache: await pageRouteModule.getIncrementalCache(baseReq, nextConfig, prerenderManifest, true),
waitUntil: event.waitUntil.bind(event),
onClose: (cb)=>{
closeController.onClose(cb);
},
onAfterTaskError: ()=>{},
onInstrumentationRequestError: (error, _request, errorContext, silenceLog)=>pageRouteModule.onRequestError(baseReq, error, errorContext, silenceLog, routerServerContext)
}
};
let finalStatus = 200;
const renderResultToResponse = (result)=>{
const varyHeader = pageRouteModule.getVaryHeader(resolvedPathname, interceptionRoutePatterns);
// Handle null responses
if (result.isNull) {
finalStatus = 500;
closeController.dispatchClose();
return new Response(null, {
status: 500
});
}
// Extract metadata
const { metadata } = result;
const headers = new Headers();
finalStatus = metadata.statusCode || baseRes.statusCode || 200;
req.fetchMetrics = metadata.fetchMetrics;
// Set content type
const contentType = result.contentType || 'text/html; charset=utf-8';
headers.set('Content-Type', contentType);
headers.set('x-edge-runtime', '1');
if (varyHeader) {
headers.set('Vary', varyHeader);
}
// Add existing headers
for (const [key, value] of Object.entries({
...baseRes.getHeaders(),
...metadata.headers
})){
if (value !== undefined) {
if (Array.isArray(value)) {
// Handle multiple header values
for (const v of value){
headers.append(key, String(v));
}
} else {
headers.set(key, String(value));
}
}
}
// Handle static response
if (!result.isDynamic) {
const body = result.toUnchunkedString();
headers.set('Content-Length', String(new TextEncoder().encode(body).length));
closeController.dispatchClose();
return new Response(body, {
status: finalStatus,
headers
});
}
// Handle dynamic/streaming response
// For edge runtime, we need to create a readable stream that pipes from the result
const { readable, writable } = new TransformStream();
// Start piping the result to the writable stream
// This is done asynchronously to avoid blocking the response creation
result.pipeTo(writable).catch((err)=>{
console.error('Error piping RenderResult to response:', err);
}).finally(()=>closeController.dispatchClose());
return new Response(readable, {
status: finalStatus,
headers
});
};
const invokeRender = async (span)=>{
try {
const result = await pageRouteModule.render(baseReq, baseRes, renderContext).finally(()=>{
if (!span) return;
span.setAttributes({
'http.status_code': finalStatus,
'next.rsc': false
});
const rootSpanAttributes = tracer.getRootSpanAttributes();
// We were unable to get attributes, probably OTEL is not enabled
if (!rootSpanAttributes) {
return;
}
if (rootSpanAttributes.get('next.span_type') !== BaseServerSpan.handleRequest) {
console.warn(`Unexpected root span type '${rootSpanAttributes.get('next.span_type')}'. Please report this Next.js issue https://github.com/vercel/next.js`);
return;
}
const route = normalizedSrcPage;
if (route) {
const name = `${req.method} ${route}`;
span.setAttributes({
'next.route': route,
'http.route': route,
'next.span_name': name
});
span.updateName(name);
} else {
span.updateName(`${req.method} ${srcPage}`);
}
});
return renderResultToResponse(result);
} catch (err) {
const silenceLog = false;
await pageRouteModule.onRequestError(baseReq, err, {
routerKind: 'App Router',
routePath: normalizedSrcPage,
routeType: 'render',
revalidateReason: undefined
}, silenceLog);
// rethrow so that we can handle serving error page
throw err;
}
};
const tracer = getTracer();
return tracer.withPropagatedContext(req.headers, ()=>tracer.trace(BaseServerSpan.handleRequest, {
spanName: `${req.method} ${srcPage}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': req.method,
'http.target': relativeUrl,
'http.route': normalizedSrcPage
}
}, invokeRender));
}
const internalHandler = (opts)=>{
return adapter({
...opts,
IncrementalCache,
handler: requestHandler,
incrementalCacheHandler,
page: 'VAR_PAGE'
});
};
export async function handler(request, ctx) {
const result = await internalHandler({
request: {
url: request.url,
method: request.method,
headers: toNodeOutgoingHttpHeaders(request.headers),
nextConfig: {
basePath: process.env.__NEXT_BASE_PATH,
i18n: process.env.__NEXT_I18N_CONFIG,
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE,
authInterrupts: Boolean(process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS),
clientParamParsingOrigins: process.env.__NEXT_CLIENT_PARAM_PARSING_ORIGINS
}
},
page: {
name: 'VAR_PAGE'
},
body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body ?? undefined : undefined,
waitUntil: ctx.waitUntil,
requestMeta: ctx.requestMeta,
signal: ctx.signal || new AbortController().signal
}
});
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, result.waitUntil);
return result.response;
}
// backwards compat
export default internalHandler;
//# sourceMappingURL=edge-ssr-app.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,301 @@
import '../../server/web/globals';
import { adapter } from '../../server/web/adapter';
import { IncrementalCache } from '../../server/lib/incremental-cache';
import * as cacheHandlers from '../../server/use-cache/handlers';
import Document from 'VAR_MODULE_DOCUMENT';
import * as appMod from 'VAR_MODULE_APP';
import * as userlandPage from 'VAR_USERLAND';
import * as userlandErrorPage from 'VAR_MODULE_GLOBAL_ERROR';
// OPTIONAL_IMPORT:* as userland500Page
// OPTIONAL_IMPORT:incrementalCacheHandler
import RouteModule from '../../server/route-modules/pages/module';
import { WebNextRequest, WebNextResponse } from '../../server/base-http/web';
import { getTracer, SpanKind } from '../../server/lib/trace/tracer';
import { BaseServerSpan } from '../../server/lib/trace/constants';
import { HTML_CONTENT_TYPE_HEADER } from '../../lib/constants';
import { toNodeOutgoingHttpHeaders } from '../../server/web/utils';
// INJECT:pageRouteModuleOptions
// INJECT:errorRouteModuleOptions
// INJECT:user500RouteModuleOptions
// INJECT_RAW:cacheHandlerImports
const pageMod = {
...userlandPage,
routeModule: new RouteModule({
...pageRouteModuleOptions,
components: {
App: appMod.default,
Document
},
userland: userlandPage,
distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',
relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || ''
})
};
const errorMod = {
...userlandErrorPage,
routeModule: new RouteModule({
...errorRouteModuleOptions,
components: {
App: appMod.default,
Document
},
userland: userlandErrorPage,
distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',
relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || ''
})
};
// FIXME: this needs to be made compatible with the template
const error500Mod = userland500Page ? {
...userland500Page,
routeModule: new RouteModule({
...user500RouteModuleOptions,
components: {
App: appMod.default,
Document
},
userland: userland500Page,
distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',
relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || ''
})
} : null;
export const ComponentMod = pageMod;
async function requestHandler(req, _event) {
var _nextConfig_i18n;
let srcPage = 'VAR_DEFINITION_PATHNAME';
const relativeUrl = `${req.nextUrl.pathname}${req.nextUrl.search}`;
const baseReq = new WebNextRequest(req);
const pageRouteModule = pageMod.routeModule;
const prepareResult = await pageRouteModule.prepare(baseReq, null, {
srcPage,
multiZoneDraftMode: false
});
if (!prepareResult) {
return new Response('Bad Request', {
status: 400
});
}
const { query, params, buildId, nextConfig, deploymentId, isNextDataRequest, buildManifest, prerenderManifest, reactLoadableManifest, subresourceIntegrityManifest, dynamicCssManifest, clientAssetToken } = prepareResult;
cacheHandlers.initializeCacheHandlers(nextConfig.cacheMaxMemorySize);
// INJECT_RAW:cacheHandlerRegistration
const renderContext = {
page: srcPage,
query,
params,
sharedContext: {
buildId,
deploymentId,
clientAssetToken,
customServer: undefined
},
renderContext: {
isFallback: false,
isDraftMode: false,
developmentNotFoundSourcePage: undefined
},
renderOpts: {
params,
page: srcPage,
supportsDynamicResponse: true,
Component: pageMod.Component,
ComponentMod: pageMod,
pageConfig: pageMod.pageConfig,
routeModule: pageMod.routeModule,
previewProps: prerenderManifest.preview,
basePath: nextConfig.basePath,
assetPrefix: nextConfig.assetPrefix,
images: nextConfig.images,
optimizeCss: nextConfig.experimental.optimizeCss,
nextConfigOutput: nextConfig.output,
nextScriptWorkers: nextConfig.experimental.nextScriptWorkers,
disableOptimizedLoading: nextConfig.experimental.disableOptimizedLoading,
domainLocales: (_nextConfig_i18n = nextConfig.i18n) == null ? void 0 : _nextConfig_i18n.domains,
distDir: '',
crossOrigin: nextConfig.crossOrigin ? nextConfig.crossOrigin : undefined,
largePageDataBytes: nextConfig.experimental.largePageDataBytes,
isExperimentalCompile: nextConfig.experimental.isExperimentalCompile,
// `htmlLimitedBots` is passed to server as serialized config in string format
experimental: {
clientTraceMetadata: nextConfig.experimental.clientTraceMetadata
},
buildManifest,
subresourceIntegrityManifest,
reactLoadableManifest,
dynamicCssManifest
}
};
let finalStatus = 200;
const renderResultToResponse = (result)=>{
// Handle null responses
if (result.isNull) {
finalStatus = 500;
return new Response(null, {
status: 500
});
}
// Extract metadata
const { metadata } = result;
finalStatus = metadata.statusCode || 200;
const headers = new Headers();
// Set content type
const contentType = result.contentType || HTML_CONTENT_TYPE_HEADER;
headers.set('Content-Type', contentType);
// Add metadata headers
if (metadata.headers) {
for (const [key, value] of Object.entries(metadata.headers)){
if (value !== undefined) {
if (Array.isArray(value)) {
// Handle multiple header values
for (const v of value){
headers.append(key, String(v));
}
} else {
headers.set(key, String(value));
}
}
}
}
// Handle static response
if (!result.isDynamic) {
const body = result.toUnchunkedString();
headers.set('Content-Length', String(new TextEncoder().encode(body).length));
return new Response(body, {
status: finalStatus,
headers
});
}
// Handle dynamic/streaming response
// For edge runtime, we need to create a readable stream that pipes from the result
const { readable, writable } = new TransformStream();
// Start piping the result to the writable stream
// This is done asynchronously to avoid blocking the response creation
result.pipeTo(writable).catch((err)=>{
console.error('Error piping RenderResult to response:', err);
});
return new Response(readable, {
status: finalStatus,
headers
});
};
const invokeRender = async (span)=>{
try {
const result = await pageRouteModule.render(// @ts-expect-error we don't type this for edge
baseReq, new WebNextResponse(undefined), {
...renderContext,
renderOpts: {
...renderContext.renderOpts,
getServerSideProps: pageMod.getServerSideProps,
Component: pageMod.default || pageMod,
ComponentMod: pageMod,
pageConfig: pageMod.config,
isNextDataRequest
}
}).finally(()=>{
if (!span) return;
span.setAttributes({
'http.status_code': finalStatus,
'next.rsc': false
});
const rootSpanAttributes = tracer.getRootSpanAttributes();
// We were unable to get attributes, probably OTEL is not enabled
if (!rootSpanAttributes) {
return;
}
if (rootSpanAttributes.get('next.span_type') !== BaseServerSpan.handleRequest) {
console.warn(`Unexpected root span type '${rootSpanAttributes.get('next.span_type')}'. Please report this Next.js issue https://github.com/vercel/next.js`);
return;
}
const route = rootSpanAttributes.get('next.route');
if (route) {
const name = `${req.method} ${route}`;
span.setAttributes({
'next.route': route,
'http.route': route,
'next.span_name': name
});
span.updateName(name);
} else {
span.updateName(`${req.method} ${srcPage}`);
}
});
return renderResultToResponse(result);
} catch (err) {
const errModule = error500Mod || errorMod;
const errRouteModule = errModule.routeModule;
if (errRouteModule.isDev) {
throw err;
}
const silenceLog = false;
await errRouteModule.onRequestError(baseReq, err, {
routerKind: 'Pages Router',
routePath: srcPage,
routeType: 'render',
revalidateReason: undefined
}, silenceLog);
const errResult = await errRouteModule.render(// @ts-expect-error we don't type this for edge
baseReq, new WebNextResponse(undefined), {
...renderContext,
page: error500Mod ? '/500' : '/_error',
renderOpts: {
...renderContext.renderOpts,
getServerSideProps: errModule.getServerSideProps,
Component: errModule.default || errModule,
ComponentMod: errModule,
pageConfig: errModule.config
}
});
return renderResultToResponse(errResult);
}
};
const tracer = getTracer();
return tracer.withPropagatedContext(req.headers, ()=>tracer.trace(BaseServerSpan.handleRequest, {
spanName: `${req.method} ${srcPage}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': req.method,
'http.target': relativeUrl,
'http.route': srcPage
}
}, invokeRender));
}
const internalHandler = (opts)=>{
return adapter({
...opts,
IncrementalCache,
handler: requestHandler,
incrementalCacheHandler,
bypassNextUrl: true,
page: 'VAR_DEFINITION_PATHNAME'
});
};
export async function handler(request, ctx) {
const result = await internalHandler({
request: {
url: request.url,
method: request.method,
headers: toNodeOutgoingHttpHeaders(request.headers),
nextConfig: {
basePath: process.env.__NEXT_BASE_PATH,
i18n: process.env.__NEXT_I18N_CONFIG,
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE,
authInterrupts: Boolean(process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS),
clientParamParsingOrigins: process.env.__NEXT_CLIENT_PARAM_PARSING_ORIGINS
}
},
page: {
name: 'VAR_DEFINITION_PATHNAME'
},
body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body ?? undefined : undefined,
waitUntil: ctx.waitUntil,
requestMeta: ctx.requestMeta,
signal: ctx.signal || new AbortController().signal
}
});
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, result.waitUntil);
return result.response;
}
// backwards compat
export default internalHandler;
//# sourceMappingURL=edge-ssr.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
// The wrapped module could be an async module, we handle that with the proxy
// here. The comma expression makes sure we don't call the function with the
// module as the "this" arg.
// Turn exports into functions that are also a thenable. This way you can await the whole object
// or exports (e.g. for Components) or call them directly as though they are async functions
// (e.g. edge functions/middleware, this is what the Edge Runtime does).
// Catch promise to prevent UnhandledPromiseRejectionWarning, this will be propagated through
// the awaited export(s) anyway.
self._ENTRIES ||= {};
const modProm = import('MODULE');
modProm.catch(()=>{});
self._ENTRIES['VAR_ENTRY_NAME'] = new Proxy(modProm, {
get (innerModProm, name) {
if (name === 'then') {
return (res, rej)=>innerModProm.then(res, rej);
}
let result = (...args)=>innerModProm.then((mod)=>(0, mod[name])(...args));
result.then = (res, rej)=>innerModProm.then((mod)=>mod[name]).then(res, rej);
return result;
}
});
//# sourceMappingURL=edge-wrapper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/build/templates/edge-wrapper.js"],"sourcesContent":["// The wrapped module could be an async module, we handle that with the proxy\n// here. The comma expression makes sure we don't call the function with the\n// module as the \"this\" arg.\n// Turn exports into functions that are also a thenable. This way you can await the whole object\n// or exports (e.g. for Components) or call them directly as though they are async functions\n// (e.g. edge functions/middleware, this is what the Edge Runtime does).\n// Catch promise to prevent UnhandledPromiseRejectionWarning, this will be propagated through\n// the awaited export(s) anyway.\nself._ENTRIES ||= {}\nconst modProm = import('MODULE')\nmodProm.catch(() => {})\nself._ENTRIES['VAR_ENTRY_NAME'] = new Proxy(modProm, {\n get(innerModProm, name) {\n if (name === 'then') {\n return (res, rej) => innerModProm.then(res, rej)\n }\n let result = (...args) =>\n innerModProm.then((mod) => (0, mod[name])(...args))\n result.then = (res, rej) =>\n innerModProm.then((mod) => mod[name]).then(res, rej)\n return result\n },\n})\n"],"names":["self","_ENTRIES","modProm","catch","Proxy","get","innerModProm","name","res","rej","then","result","args","mod"],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,4BAA4B;AAC5B,gGAAgG;AAChG,6FAA6F;AAC7F,wEAAwE;AACxE,6FAA6F;AAC7F,gCAAgC;AAChCA,KAAKC,QAAQ,KAAK,CAAC;AACnB,MAAMC,UAAU,MAAM,CAAC;AACvBA,QAAQC,KAAK,CAAC,KAAO;AACrBH,KAAKC,QAAQ,CAAC,iBAAiB,GAAG,IAAIG,MAAMF,SAAS;IACnDG,KAAIC,YAAY,EAAEC,IAAI;QACpB,IAAIA,SAAS,QAAQ;YACnB,OAAO,CAACC,KAAKC,MAAQH,aAAaI,IAAI,CAACF,KAAKC;QAC9C;QACA,IAAIE,SAAS,CAAC,GAAGC,OACfN,aAAaI,IAAI,CAAC,CAACG,MAAQ,AAAC,CAAA,GAAGA,GAAG,CAACN,KAAK,AAAD,KAAMK;QAC/CD,OAAOD,IAAI,GAAG,CAACF,KAAKC,MAClBH,aAAaI,IAAI,CAAC,CAACG,MAAQA,GAAG,CAACN,KAAK,EAAEG,IAAI,CAACF,KAAKC;QAClD,OAAOE;IACT;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,26 @@
/**
* Hoists a name from a module or promised module.
*
* @param module the module to hoist the name from
* @param name the name to hoist
* @returns the value on the module (or promised module)
*/ export function hoist(module, name) {
// If the name is available in the module, return it.
if (name in module) {
return module[name];
}
// If a property called `then` exists, assume it's a promise and
// return a promise that resolves to the name.
if ('then' in module && typeof module.then === 'function') {
return module.then((mod)=>hoist(mod, name));
}
// If we're trying to hoise the default export, and the module is a function,
// return the module itself.
if (typeof module === 'function' && name === 'default') {
return module;
}
// Otherwise, return undefined.
return undefined;
}
//# sourceMappingURL=helpers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/build/templates/helpers.ts"],"sourcesContent":["/**\n * Hoists a name from a module or promised module.\n *\n * @param module the module to hoist the name from\n * @param name the name to hoist\n * @returns the value on the module (or promised module)\n */\nexport function hoist(module: any, name: string) {\n // If the name is available in the module, return it.\n if (name in module) {\n return module[name]\n }\n\n // If a property called `then` exists, assume it's a promise and\n // return a promise that resolves to the name.\n if ('then' in module && typeof module.then === 'function') {\n return module.then((mod: any) => hoist(mod, name))\n }\n\n // If we're trying to hoise the default export, and the module is a function,\n // return the module itself.\n if (typeof module === 'function' && name === 'default') {\n return module\n }\n\n // Otherwise, return undefined.\n return undefined\n}\n"],"names":["hoist","module","name","then","mod","undefined"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,MAAMC,MAAW,EAAEC,IAAY;IAC7C,qDAAqD;IACrD,IAAIA,QAAQD,QAAQ;QAClB,OAAOA,MAAM,CAACC,KAAK;IACrB;IAEA,gEAAgE;IAChE,8CAA8C;IAC9C,IAAI,UAAUD,UAAU,OAAOA,OAAOE,IAAI,KAAK,YAAY;QACzD,OAAOF,OAAOE,IAAI,CAAC,CAACC,MAAaJ,MAAMI,KAAKF;IAC9C;IAEA,6EAA6E;IAC7E,4BAA4B;IAC5B,IAAI,OAAOD,WAAW,cAAcC,SAAS,WAAW;QACtD,OAAOD;IACT;IAEA,+BAA+B;IAC/B,OAAOI;AACT","ignoreList":[0]}

View File

@@ -0,0 +1,101 @@
import '../adapter/setup-node-env.external';
import '../../server/web/globals';
import { adapter } from '../../server/web/adapter';
import { IncrementalCache } from '../../server/lib/incremental-cache';
// OPTIONAL_IMPORT:incrementalCacheHandler
// Import the userland code.
import * as _mod from 'VAR_USERLAND';
import { edgeInstrumentationOnRequestError } from '../../server/web/globals';
import { isNextRouterError } from '../../client/components/is-next-router-error';
import { toNodeOutgoingHttpHeaders } from '../../server/web/utils';
const mod = {
..._mod
};
const page = 'VAR_DEFINITION_PAGE';
const isProxy = page === '/proxy' || page === '/src/proxy';
const handlerUserland = (isProxy ? mod.proxy : mod.middleware) || mod.default;
class ProxyMissingExportError extends Error {
constructor(message){
super(message);
// Stack isn't useful here, remove it considering it spams logs during development.
this.stack = '';
}
}
// TODO: This spams logs during development. Find a better way to handle this.
// Removing this will spam "fn is not a function" logs which is worse.
if (typeof handlerUserland !== 'function') {
throw new ProxyMissingExportError(`The ${isProxy ? 'Proxy' : 'Middleware'} file "${page}" must export a function named \`${isProxy ? 'proxy' : 'middleware'}\` or a default function.`);
}
// Proxy will only sent out the FetchEvent to next server,
// so load instrumentation module here and track the error inside proxy module.
function errorHandledHandler(fn) {
return async (...args)=>{
try {
return await fn(...args);
} catch (err) {
// In development, error the navigation API usage in runtime,
// since it's not allowed to be used in proxy as it's outside of react component tree.
if (process.env.NODE_ENV !== 'production') {
if (isNextRouterError(err)) {
err.message = `Next.js navigation API is not allowed to be used in ${isProxy ? 'Proxy' : 'Middleware'}.`;
throw err;
}
}
const req = args[0];
const url = new URL(req.url);
const resource = url.pathname + url.search;
await edgeInstrumentationOnRequestError(err, {
path: resource,
method: req.method,
headers: Object.fromEntries(req.headers.entries())
}, {
routerKind: 'Pages Router',
routePath: '/proxy',
routeType: 'proxy',
revalidateReason: undefined
});
throw err;
}
};
}
const internalHandler = (opts)=>{
return adapter({
...opts,
IncrementalCache,
incrementalCacheHandler,
page,
handler: errorHandledHandler(handlerUserland)
});
};
export async function handler(request, ctx) {
const result = await internalHandler({
request: {
url: request.url,
method: request.method,
headers: toNodeOutgoingHttpHeaders(request.headers),
nextConfig: {
basePath: process.env.__NEXT_BASE_PATH,
i18n: process.env.__NEXT_I18N_CONFIG,
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE,
authInterrupts: Boolean(process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS),
clientParamParsingOrigins: process.env.__NEXT_CLIENT_PARAM_PARSING_ORIGINS
}
},
page: {
name: page
},
body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body ?? undefined : undefined,
waitUntil: ctx.waitUntil,
requestMeta: ctx.requestMeta,
signal: ctx.signal || new AbortController().signal
}
});
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, result.waitUntil);
return result.response;
}
// backwards compat
export default internalHandler;
//# sourceMappingURL=middleware.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,141 @@
import { sendError } from '../../server/api-utils';
import { RouteKind } from '../../server/route-kind';
import { PagesAPIRouteModule } from '../../server/route-modules/pages-api/module.compiled';
import { hoist } from './helpers';
// Import the userland code.
import * as userland from 'VAR_USERLAND';
import { getTracer, SpanKind } from '../../server/lib/trace/tracer';
import { BaseServerSpan } from '../../server/lib/trace/constants';
import { addRequestMeta, setRequestMeta } from '../../server/request-meta';
// Re-export the handler (should be the default export).
export default hoist(userland, 'default');
// Re-export config.
export const config = hoist(userland, 'config');
// Create and export the route module that will be consumed.
const routeModule = new PagesAPIRouteModule({
definition: {
kind: RouteKind.PAGES_API,
page: 'VAR_DEFINITION_PAGE',
pathname: 'VAR_DEFINITION_PATHNAME',
// The following aren't used in production.
bundlePath: '',
filename: ''
},
userland,
distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',
relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || ''
});
export async function handler(req, res, ctx) {
if (ctx.requestMeta) {
setRequestMeta(req, ctx.requestMeta);
}
if (routeModule.isDev) {
addRequestMeta(req, 'devRequestTimingInternalsEnd', process.hrtime.bigint());
}
let srcPage = 'VAR_DEFINITION_PAGE';
// turbopack doesn't normalize `/index` in the page name
// so we need to to process dynamic routes properly
// TODO: fix turbopack providing differing value from webpack
if (process.env.TURBOPACK) {
srcPage = srcPage.replace(/\/index$/, '') || '/';
}
const prepareResult = await routeModule.prepare(req, res, {
srcPage
});
if (!prepareResult) {
res.statusCode = 400;
res.end('Bad Request');
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, Promise.resolve());
return;
}
const { query, params, prerenderManifest, routerServerContext } = prepareResult;
try {
const method = req.method || 'GET';
const tracer = getTracer();
const activeSpan = tracer.getActiveScopeSpan();
const isWrappedByNextServer = Boolean(routerServerContext == null ? void 0 : routerServerContext.isWrappedByNextServer);
const onRequestError = routeModule.instrumentationOnRequestError.bind(routeModule);
let parentSpan;
const invokeRouteModule = async (span)=>routeModule.render(req, res, {
query: {
...query,
...params
},
params,
allowedRevalidateHeaderKeys: process.env.__NEXT_ALLOWED_REVALIDATE_HEADERS,
multiZoneDraftMode: Boolean(process.env.__NEXT_MULTI_ZONE_DRAFT_MODE),
trustHostHeader: process.env.__NEXT_TRUST_HOST_HEADER,
// TODO: get this from from runtime env so manifest
// doesn't need to load
previewProps: prerenderManifest.preview,
propagateError: false,
dev: routeModule.isDev,
page: 'VAR_DEFINITION_PAGE',
internalRevalidate: routerServerContext == null ? void 0 : routerServerContext.revalidate,
onError: (...args)=>onRequestError(req, ...args)
}).finally(()=>{
if (!span) return;
span.setAttributes({
'http.status_code': res.statusCode,
'next.rsc': false
});
const rootSpanAttributes = tracer.getRootSpanAttributes();
// We were unable to get attributes, probably OTEL is not enabled
if (!rootSpanAttributes) {
return;
}
if (rootSpanAttributes.get('next.span_type') !== BaseServerSpan.handleRequest) {
console.warn(`Unexpected root span type '${rootSpanAttributes.get('next.span_type')}'. Please report this Next.js issue https://github.com/vercel/next.js`);
return;
}
const route = rootSpanAttributes.get('next.route');
if (route) {
const name = `${method} ${route}`;
span.setAttributes({
'next.route': route,
'http.route': route,
'next.span_name': name
});
span.updateName(name);
// Propagate http.route to the parent span if one exists (e.g.
// a platform-created HTTP span in adapter deployments).
if (parentSpan && parentSpan !== span) {
parentSpan.setAttribute('http.route', route);
parentSpan.updateName(name);
}
} else {
span.updateName(`${method} ${srcPage}`);
}
});
// TODO: activeSpan code path is for when wrapped by
// next-server can be removed when this is no longer used
if (isWrappedByNextServer && activeSpan) {
await invokeRouteModule(activeSpan);
} else {
parentSpan = tracer.getActiveScopeSpan();
await tracer.withPropagatedContext(req.headers, ()=>tracer.trace(BaseServerSpan.handleRequest, {
spanName: `${method} ${srcPage}`,
kind: SpanKind.SERVER,
attributes: {
'http.method': method,
'http.target': req.url
}
}, invokeRouteModule), undefined, !isWrappedByNextServer);
}
} catch (err) {
// we re-throw in dev to show the error overlay
if (routeModule.isDev) {
throw err;
}
// this is technically an invariant as error handling
// should be done inside of api-resolver onError
sendError(res, 500, 'Internal Server Error');
} finally{
// We don't allow any waitUntil work in pages API routes currently
// so if callback is present return with resolved promise since no
// pending work
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, Promise.resolve());
}
}
//# sourceMappingURL=pages-api.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,57 @@
import '../../server/web/globals';
import { adapter } from '../../server/web/adapter';
import { IncrementalCache } from '../../server/lib/incremental-cache';
import { wrapApiHandler } from '../../server/api-utils';
// OPTIONAL_IMPORT:incrementalCacheHandler
// Import the userland code.
import handlerUserland from 'VAR_USERLAND';
import { toNodeOutgoingHttpHeaders } from '../../server/web/utils';
const page = 'VAR_DEFINITION_PAGE';
if (typeof handlerUserland !== 'function') {
throw Object.defineProperty(new Error(`The Edge Function "pages${page}" must export a \`default\` function`), "__NEXT_ERROR_CODE", {
value: "E1011",
enumerable: false,
configurable: true
});
}
const internalHandler = (opts)=>{
return adapter({
...opts,
IncrementalCache,
incrementalCacheHandler,
page: 'VAR_DEFINITION_PATHNAME',
handler: wrapApiHandler(page, handlerUserland)
});
};
export async function handler(request, ctx) {
const result = await internalHandler({
request: {
url: request.url,
method: request.method,
headers: toNodeOutgoingHttpHeaders(request.headers),
nextConfig: {
basePath: process.env.__NEXT_BASE_PATH,
i18n: process.env.__NEXT_I18N_CONFIG,
trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),
experimental: {
cacheLife: process.env.__NEXT_CACHE_LIFE,
authInterrupts: Boolean(process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS),
clientParamParsingOrigins: process.env.__NEXT_CLIENT_PARAM_PARSING_ORIGINS
}
},
page: {
name: 'VAR_DEFINITION_PATHNAME'
},
body: request.method !== 'GET' && request.method !== 'HEAD' ? request.body ?? undefined : undefined,
waitUntil: ctx.waitUntil,
requestMeta: ctx.requestMeta,
signal: ctx.signal || new AbortController().signal
}
});
ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, result.waitUntil);
return result.response;
}
// backwards compat
export default internalHandler;
//# sourceMappingURL=pages-edge-api.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/build/templates/pages-edge-api.ts"],"sourcesContent":["import type { EdgeHandler } from '../../server/web/adapter'\n\nimport '../../server/web/globals'\n\nimport { adapter } from '../../server/web/adapter'\nimport { IncrementalCache } from '../../server/lib/incremental-cache'\nimport { wrapApiHandler } from '../../server/api-utils'\ndeclare const incrementalCacheHandler: any\n// OPTIONAL_IMPORT:incrementalCacheHandler\n\n// Import the userland code.\nimport handlerUserland from 'VAR_USERLAND'\nimport { toNodeOutgoingHttpHeaders } from '../../server/web/utils'\nimport type { RequestMeta } from '../../server/request-meta'\n\nconst page = 'VAR_DEFINITION_PAGE'\n\nif (typeof handlerUserland !== 'function') {\n throw new Error(\n `The Edge Function \"pages${page}\" must export a \\`default\\` function`\n )\n}\n\nconst internalHandler: EdgeHandler = (opts) => {\n return adapter({\n ...opts,\n IncrementalCache,\n incrementalCacheHandler,\n page: 'VAR_DEFINITION_PATHNAME',\n handler: wrapApiHandler(page, handlerUserland),\n })\n}\n\nexport async function handler(\n request: Request,\n ctx: {\n waitUntil?: (prom: Promise<void>) => void\n signal?: AbortSignal\n requestMeta?: RequestMeta\n }\n): Promise<Response> {\n const result = await internalHandler({\n request: {\n url: request.url,\n method: request.method,\n headers: toNodeOutgoingHttpHeaders(request.headers),\n nextConfig: {\n basePath: process.env.__NEXT_BASE_PATH,\n i18n: process.env.__NEXT_I18N_CONFIG as any,\n trailingSlash: Boolean(process.env.__NEXT_TRAILING_SLASH),\n experimental: {\n cacheLife: process.env.__NEXT_CACHE_LIFE as any,\n authInterrupts: Boolean(\n process.env.__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS\n ),\n clientParamParsingOrigins: process.env\n .__NEXT_CLIENT_PARAM_PARSING_ORIGINS as any,\n },\n },\n page: {\n name: 'VAR_DEFINITION_PATHNAME',\n },\n body:\n request.method !== 'GET' && request.method !== 'HEAD'\n ? (request.body ?? undefined)\n : undefined,\n waitUntil: ctx.waitUntil,\n requestMeta: ctx.requestMeta,\n signal: ctx.signal || new AbortController().signal,\n },\n })\n\n ctx.waitUntil?.(result.waitUntil)\n\n return result.response\n}\n\n// backwards compat\nexport default internalHandler\n"],"names":["adapter","IncrementalCache","wrapApiHandler","handlerUserland","toNodeOutgoingHttpHeaders","page","Error","internalHandler","opts","incrementalCacheHandler","handler","request","ctx","result","url","method","headers","nextConfig","basePath","process","env","__NEXT_BASE_PATH","i18n","__NEXT_I18N_CONFIG","trailingSlash","Boolean","__NEXT_TRAILING_SLASH","experimental","cacheLife","__NEXT_CACHE_LIFE","authInterrupts","__NEXT_EXPERIMENTAL_AUTH_INTERRUPTS","clientParamParsingOrigins","__NEXT_CLIENT_PARAM_PARSING_ORIGINS","name","body","undefined","waitUntil","requestMeta","signal","AbortController","response"],"mappings":"AAEA,OAAO,2BAA0B;AAEjC,SAASA,OAAO,QAAQ,2BAA0B;AAClD,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,cAAc,QAAQ,yBAAwB;AAEvD,0CAA0C;AAE1C,4BAA4B;AAC5B,OAAOC,qBAAqB,eAAc;AAC1C,SAASC,yBAAyB,QAAQ,yBAAwB;AAGlE,MAAMC,OAAO;AAEb,IAAI,OAAOF,oBAAoB,YAAY;IACzC,MAAM,qBAEL,CAFK,IAAIG,MACR,CAAC,wBAAwB,EAAED,KAAK,oCAAoC,CAAC,GADjE,qBAAA;eAAA;oBAAA;sBAAA;IAEN;AACF;AAEA,MAAME,kBAA+B,CAACC;IACpC,OAAOR,QAAQ;QACb,GAAGQ,IAAI;QACPP;QACAQ;QACAJ,MAAM;QACNK,SAASR,eAAeG,MAAMF;IAChC;AACF;AAEA,OAAO,eAAeO,QACpBC,OAAgB,EAChBC,GAIC;IAED,MAAMC,SAAS,MAAMN,gBAAgB;QACnCI,SAAS;YACPG,KAAKH,QAAQG,GAAG;YAChBC,QAAQJ,QAAQI,MAAM;YACtBC,SAASZ,0BAA0BO,QAAQK,OAAO;YAClDC,YAAY;gBACVC,UAAUC,QAAQC,GAAG,CAACC,gBAAgB;gBACtCC,MAAMH,QAAQC,GAAG,CAACG,kBAAkB;gBACpCC,eAAeC,QAAQN,QAAQC,GAAG,CAACM,qBAAqB;gBACxDC,cAAc;oBACZC,WAAWT,QAAQC,GAAG,CAACS,iBAAiB;oBACxCC,gBAAgBL,QACdN,QAAQC,GAAG,CAACW,mCAAmC;oBAEjDC,2BAA2Bb,QAAQC,GAAG,CACnCa,mCAAmC;gBACxC;YACF;YACA5B,MAAM;gBACJ6B,MAAM;YACR;YACAC,MACExB,QAAQI,MAAM,KAAK,SAASJ,QAAQI,MAAM,KAAK,SAC1CJ,QAAQwB,IAAI,IAAIC,YACjBA;YACNC,WAAWzB,IAAIyB,SAAS;YACxBC,aAAa1B,IAAI0B,WAAW;YAC5BC,QAAQ3B,IAAI2B,MAAM,IAAI,IAAIC,kBAAkBD,MAAM;QACpD;IACF;IAEA3B,IAAIyB,SAAS,oBAAbzB,IAAIyB,SAAS,MAAbzB,KAAgBC,OAAOwB,SAAS;IAEhC,OAAOxB,OAAO4B,QAAQ;AACxB;AAEA,mBAAmB;AACnB,eAAelC,gBAAe","ignoreList":[0]}

View File

@@ -0,0 +1,53 @@
import { PagesRouteModule } from '../../server/route-modules/pages/module.compiled';
import { RouteKind } from '../../server/route-kind';
import { hoist } from './helpers';
// Import the app and document modules.
import * as document from 'VAR_MODULE_DOCUMENT';
import * as app from 'VAR_MODULE_APP';
// Import the userland code.
import * as userland from 'VAR_USERLAND';
import { getHandler } from '../../server/route-modules/pages/pages-handler';
// Re-export the component (should be the default export).
export default hoist(userland, 'default');
// Re-export methods.
export const getStaticProps = hoist(userland, 'getStaticProps');
export const getStaticPaths = hoist(userland, 'getStaticPaths');
export const getServerSideProps = hoist(userland, 'getServerSideProps');
export const config = hoist(userland, 'config');
export const reportWebVitals = hoist(userland, 'reportWebVitals');
// Re-export legacy methods.
export const unstable_getStaticProps = hoist(userland, 'unstable_getStaticProps');
export const unstable_getStaticPaths = hoist(userland, 'unstable_getStaticPaths');
export const unstable_getStaticParams = hoist(userland, 'unstable_getStaticParams');
export const unstable_getServerProps = hoist(userland, 'unstable_getServerProps');
export const unstable_getServerSideProps = hoist(userland, 'unstable_getServerSideProps');
// Create and export the route module that will be consumed.
export const routeModule = new PagesRouteModule({
definition: {
kind: RouteKind.PAGES,
page: 'VAR_DEFINITION_PAGE',
pathname: 'VAR_DEFINITION_PATHNAME',
// The following aren't used in production.
bundlePath: '',
filename: ''
},
distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',
relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || '',
components: {
// default export might not exist when optimized for data only
App: app.default,
Document: document.default
},
userland
});
export const handler = getHandler({
srcPage: 'VAR_DEFINITION_PAGE',
config,
userland,
routeModule,
getStaticPaths,
getStaticProps,
getServerSideProps
});
//# sourceMappingURL=pages.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/build/templates/pages.ts"],"sourcesContent":["import { PagesRouteModule } from '../../server/route-modules/pages/module.compiled'\nimport { RouteKind } from '../../server/route-kind'\n\nimport { hoist } from './helpers'\n\n// Import the app and document modules.\nimport * as document from 'VAR_MODULE_DOCUMENT'\nimport * as app from 'VAR_MODULE_APP'\n\n// Import the userland code.\nimport * as userland from 'VAR_USERLAND'\nimport { getHandler } from '../../server/route-modules/pages/pages-handler'\n\n// Re-export the component (should be the default export).\nexport default hoist(userland, 'default')\n\n// Re-export methods.\nexport const getStaticProps = hoist(userland, 'getStaticProps')\nexport const getStaticPaths = hoist(userland, 'getStaticPaths')\nexport const getServerSideProps = hoist(userland, 'getServerSideProps')\nexport const config = hoist(userland, 'config')\nexport const reportWebVitals = hoist(userland, 'reportWebVitals')\n\n// Re-export legacy methods.\nexport const unstable_getStaticProps = hoist(\n userland,\n 'unstable_getStaticProps'\n)\nexport const unstable_getStaticPaths = hoist(\n userland,\n 'unstable_getStaticPaths'\n)\nexport const unstable_getStaticParams = hoist(\n userland,\n 'unstable_getStaticParams'\n)\nexport const unstable_getServerProps = hoist(\n userland,\n 'unstable_getServerProps'\n)\nexport const unstable_getServerSideProps = hoist(\n userland,\n 'unstable_getServerSideProps'\n)\n\n// Create and export the route module that will be consumed.\nexport const routeModule = new PagesRouteModule({\n definition: {\n kind: RouteKind.PAGES,\n page: 'VAR_DEFINITION_PAGE',\n pathname: 'VAR_DEFINITION_PATHNAME',\n // The following aren't used in production.\n bundlePath: '',\n filename: '',\n },\n distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',\n relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || '',\n components: {\n // default export might not exist when optimized for data only\n App: app.default,\n Document: document.default,\n },\n userland,\n})\n\nexport const handler = getHandler({\n srcPage: 'VAR_DEFINITION_PAGE',\n config,\n userland,\n routeModule,\n getStaticPaths,\n getStaticProps,\n getServerSideProps,\n})\n"],"names":["PagesRouteModule","RouteKind","hoist","document","app","userland","getHandler","getStaticProps","getStaticPaths","getServerSideProps","config","reportWebVitals","unstable_getStaticProps","unstable_getStaticPaths","unstable_getStaticParams","unstable_getServerProps","unstable_getServerSideProps","routeModule","definition","kind","PAGES","page","pathname","bundlePath","filename","distDir","process","env","__NEXT_RELATIVE_DIST_DIR","relativeProjectDir","__NEXT_RELATIVE_PROJECT_DIR","components","App","default","Document","handler","srcPage"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,mDAAkD;AACnF,SAASC,SAAS,QAAQ,0BAAyB;AAEnD,SAASC,KAAK,QAAQ,YAAW;AAEjC,uCAAuC;AACvC,YAAYC,cAAc,sBAAqB;AAC/C,YAAYC,SAAS,iBAAgB;AAErC,4BAA4B;AAC5B,YAAYC,cAAc,eAAc;AACxC,SAASC,UAAU,QAAQ,iDAAgD;AAE3E,0DAA0D;AAC1D,eAAeJ,MAAMG,UAAU,WAAU;AAEzC,qBAAqB;AACrB,OAAO,MAAME,iBAAiBL,MAAMG,UAAU,kBAAiB;AAC/D,OAAO,MAAMG,iBAAiBN,MAAMG,UAAU,kBAAiB;AAC/D,OAAO,MAAMI,qBAAqBP,MAAMG,UAAU,sBAAqB;AACvE,OAAO,MAAMK,SAASR,MAAMG,UAAU,UAAS;AAC/C,OAAO,MAAMM,kBAAkBT,MAAMG,UAAU,mBAAkB;AAEjE,4BAA4B;AAC5B,OAAO,MAAMO,0BAA0BV,MACrCG,UACA,2BACD;AACD,OAAO,MAAMQ,0BAA0BX,MACrCG,UACA,2BACD;AACD,OAAO,MAAMS,2BAA2BZ,MACtCG,UACA,4BACD;AACD,OAAO,MAAMU,0BAA0Bb,MACrCG,UACA,2BACD;AACD,OAAO,MAAMW,8BAA8Bd,MACzCG,UACA,+BACD;AAED,4DAA4D;AAC5D,OAAO,MAAMY,cAAc,IAAIjB,iBAAiB;IAC9CkB,YAAY;QACVC,MAAMlB,UAAUmB,KAAK;QACrBC,MAAM;QACNC,UAAU;QACV,2CAA2C;QAC3CC,YAAY;QACZC,UAAU;IACZ;IACAC,SAASC,QAAQC,GAAG,CAACC,wBAAwB,IAAI;IACjDC,oBAAoBH,QAAQC,GAAG,CAACG,2BAA2B,IAAI;IAC/DC,YAAY;QACV,8DAA8D;QAC9DC,KAAK5B,IAAI6B,OAAO;QAChBC,UAAU/B,SAAS8B,OAAO;IAC5B;IACA5B;AACF,GAAE;AAEF,OAAO,MAAM8B,UAAU7B,WAAW;IAChC8B,SAAS;IACT1B;IACAL;IACAY;IACAT;IACAD;IACAE;AACF,GAAE","ignoreList":[0]}