| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/server/ |
Upload File : |
import { createRequestContext, runWithRequestContext } from "../shims/unified-request-context.js";
import { getRequestExecutionContext } from "../shims/request-context.js";
import { reportRequestError } from "./instrumentation.js";
import { consumeDynamicUsage, getAndClearPendingCookies, getDraftModeCookieHeader, markDynamicUsage, setHeadersAccessPhase } from "../shims/headers.js";
import { ensureFetchPatch, getCollectedFetchTags, setCurrentFetchSoftTags } from "../shims/fetch-cache.js";
import { setNavigationContext } from "../shims/navigation.js";
import { makeThenableParams } from "../shims/thenable-params.js";
import { isKnownDynamicAppRoute, isValidHTTPMethod } from "./app-route-handler-runtime.js";
import { getAppRouteHandlerRevalidateSeconds, hasAppRouteHandlerDefaultExport, resolveAppRouteHandlerMethod, shouldReadAppRouteHandlerCache } from "./app-route-handler-policy.js";
import { createStaticGenerationHeadersContext } from "./app-static-generation.js";
import { buildPageCacheTags } from "./implicit-tags.js";
import { applyRouteHandlerMiddlewareContext } from "./app-route-handler-response.js";
import { executeAppRouteHandler } from "./app-route-handler-execution.js";
import { readAppRouteHandlerCacheResponse } from "./app-route-handler-cache.js";
//#region src/server/app-route-handler-dispatch.ts
function isAppRouteHandlerFunction(value) {
return typeof value === "function";
}
function buildRouteHandlerPageCacheTags(pathname, extraTags, routeSegments) {
return buildPageCacheTags(pathname, extraTags, routeSegments, "route");
}
async function runInRouteHandlerRevalidationContext(options, renderFn) {
await runWithRequestContext(createRequestContext({
headersContext: createStaticGenerationHeadersContext({
dynamicConfig: options.dynamicConfig,
routeKind: "route",
routePattern: options.routePattern
}),
executionContext: getRequestExecutionContext(),
unstableCacheRevalidation: "foreground"
}), async () => {
ensureFetchPatch();
setCurrentFetchSoftTags(buildRouteHandlerPageCacheTags(options.cleanPathname, [], options.routeSegments));
await renderFn();
});
}
async function dispatchAppRouteHandler(options) {
const { route } = options;
const handler = route.routeHandler;
const method = options.request.method.toUpperCase();
const revalidateSeconds = getAppRouteHandlerRevalidateSeconds(handler);
const isDevelopment = options.isDevelopment ?? process.env.NODE_ENV === "development";
const isProduction = options.isProduction ?? process.env.NODE_ENV === "production";
if (hasAppRouteHandlerDefaultExport(handler) && isDevelopment) console.error("[vinext] Detected default export in route handler " + route.pattern + ". Export a named export for each HTTP method instead.");
if (!isValidHTTPMethod(method)) {
options.clearRequestContext();
return applyRouteHandlerMiddlewareContext(new Response(null, { status: 400 }), options.middlewareContext);
}
const { allowHeaderForOptions, handlerFn, isAutoHead, shouldAutoRespondToOptions } = resolveAppRouteHandlerMethod(handler, method);
if (shouldAutoRespondToOptions) {
options.clearRequestContext();
return applyRouteHandlerMiddlewareContext(new Response(null, {
status: 204,
headers: { Allow: allowHeaderForOptions }
}), options.middlewareContext);
}
const resolvedHandlerFn = isAppRouteHandlerFunction(handlerFn) ? handlerFn : void 0;
if (revalidateSeconds !== null && shouldReadAppRouteHandlerCache({
dynamicConfig: handler.dynamic,
handlerFn: resolvedHandlerFn,
isAutoHead,
isKnownDynamic: isKnownDynamicAppRoute(route.pattern),
isProduction,
method,
revalidateSeconds
}) && resolvedHandlerFn) {
const cachedRouteResponse = await readAppRouteHandlerCacheResponse({
basePath: options.basePath,
buildPageCacheTags(pathname, extraTags) {
return buildRouteHandlerPageCacheTags(pathname, extraTags, route.routeSegments);
},
cleanPathname: options.cleanPathname,
clearRequestContext: options.clearRequestContext,
consumeDynamicUsage,
dynamicConfig: handler.dynamic,
getCollectedFetchTags,
handlerFn: resolvedHandlerFn,
i18n: options.i18n,
isAutoHead,
isrDebug: options.isrDebug,
isrGet: options.isrGet,
isrRouteKey: options.isrRouteKey,
isrSet: options.isrSet,
markDynamicUsage,
middlewareContext: options.middlewareContext,
params: options.params,
requestUrl: options.request.url,
revalidateSearchParams: options.searchParams,
expireSeconds: options.expireSeconds,
revalidateSeconds,
routePattern: route.pattern,
runInRevalidationContext(renderFn) {
return runInRouteHandlerRevalidationContext({
cleanPathname: options.cleanPathname,
dynamicConfig: handler.dynamic,
routePattern: route.pattern,
routeSegments: route.routeSegments
}, renderFn);
},
scheduleBackgroundRegeneration(key, renderFn) {
options.scheduleBackgroundRegeneration(key, renderFn, {
routerKind: "App Router",
routePath: route.pattern,
routeType: "route"
});
},
setHeadersAccessPhase,
setNavigationContext
});
if (cachedRouteResponse) return cachedRouteResponse;
}
if (resolvedHandlerFn) return executeAppRouteHandler({
basePath: options.basePath,
buildPageCacheTags(pathname, extraTags) {
return buildRouteHandlerPageCacheTags(pathname, extraTags, route.routeSegments);
},
cleanPathname: options.cleanPathname,
clearRequestContext: options.clearRequestContext,
consumeDynamicUsage,
executionContext: getRequestExecutionContext(),
getAndClearPendingCookies,
getCollectedFetchTags,
getDraftModeCookieHeader,
handler,
handlerFn: resolvedHandlerFn,
i18n: options.i18n,
isAutoHead,
isProduction,
isrDebug: options.isrDebug,
isrRouteKey: options.isrRouteKey,
isrSet: options.isrSet,
markDynamicUsage,
method,
middlewareContext: options.middlewareContext,
middlewareRequestHeaders: options.middlewareRequestHeaders,
params: makeThenableParams(options.params),
reportRequestError(error, request, context) {
reportRequestError(error, request, context);
},
request: options.request,
expireSeconds: options.expireSeconds,
revalidateSeconds,
routePattern: route.pattern,
setHeadersAccessPhase
});
options.clearRequestContext();
return applyRouteHandlerMiddlewareContext(new Response(null, { status: 405 }), options.middlewareContext);
}
//#endregion
export { dispatchAppRouteHandler };
//# sourceMappingURL=app-route-handler-dispatch.js.map