///
///
///
import type { __ApiPreviewProps } from './api-utils';
import type { DomainLocale } from './config';
import type { FontManifest, FontConfig } from './font-utils';
import type { LoadComponentsReturnType } from './load-components';
import type { MiddlewareRouteMatch } from '../shared/lib/router/utils/middleware-route-matcher';
import type { Params } from '../shared/lib/router/utils/route-matcher';
import type { NextConfig, NextConfigComplete } from './config-shared';
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta';
import type { ParsedUrlQuery } from 'querystring';
import type { RenderOptsPartial as PagesRenderOptsPartial } from './render';
import type { RenderOptsPartial as AppRenderOptsPartial } from './app-render/types';
import type { ResponseCacheBase } from './response-cache';
import type { UrlWithParsedQuery } from 'url';
import type { ServerRuntime, SizeLimit } from 'next/types';
import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin';
import type { BaseNextRequest, BaseNextResponse } from './base-http';
import type { PayloadOptions } from './send-payload';
import type { ManifestRewriteRoute, ManifestRoute, PrerenderManifest } from '../build';
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin';
import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin';
import type { PagesAPIRouteMatch } from './future/route-matches/pages-api-route-match';
import type { Server as HTTPServer } from 'http';
import RenderResult from './render-result';
import type { ImageConfigComplete } from '../shared/lib/image-config';
import type { MiddlewareMatcher } from '../build/analysis/get-page-static-info';
import type { RouteMatcherManager } from './future/route-matcher-managers/route-matcher-manager';
import { LocaleRouteNormalizer } from './future/normalizers/locale-route-normalizer';
import { I18NProvider } from './future/helpers/i18n-provider';
export type FindComponentsResult = {
components: LoadComponentsReturnType;
query: NextParsedUrlQuery;
};
export interface MiddlewareRoutingItem {
page: string;
match: MiddlewareRouteMatch;
matchers?: MiddlewareMatcher[];
}
/**
* The normalized route manifest is the same as the route manifest, but with
* the rewrites normalized to the object shape that the router expects.
*/
export type NormalizedRouteManifest = {
readonly dynamicRoutes: ReadonlyArray;
readonly rewrites: {
readonly beforeFiles: ReadonlyArray;
readonly afterFiles: ReadonlyArray;
readonly fallback: ReadonlyArray;
};
};
export interface Options {
/**
* Object containing the configuration next.config.js
*/
conf: NextConfig;
/**
* Set to false when the server was created by Next.js
*/
customServer?: boolean;
/**
* Tells if Next.js is running in dev mode
*/
dev?: boolean;
/**
* Enables the experimental testing mode.
*/
experimentalTestProxy?: boolean;
/**
* Whether or not the dev server is running in experimental HTTPS mode
*/
experimentalHttpsServer?: boolean;
/**
* Where the Next project is located
*/
dir?: string;
/**
* Tells if Next.js is at the platform-level
*/
minimalMode?: boolean;
/**
* Hide error messages containing server information
*/
quiet?: boolean;
/**
* The hostname the server is running behind
*/
hostname?: string;
/**
* The port the server is running behind
*/
port?: number;
/**
* The HTTP Server that Next.js is running behind
*/
httpServer?: HTTPServer;
isNodeDebugging?: 'brk' | boolean;
}
export type RenderOpts = PagesRenderOptsPartial & AppRenderOptsPartial;
export type LoadedRenderOpts = RenderOpts & LoadComponentsReturnType;
type BaseRenderOpts = {
deploymentId?: string;
poweredByHeader: boolean;
buildId: string;
generateEtags: boolean;
runtimeConfig?: {
[key: string]: any;
};
assetPrefix?: string;
canonicalBase: string;
dev?: boolean;
previewProps: __ApiPreviewProps;
customServer?: boolean;
ampOptimizerConfig?: {
[key: string]: any;
};
basePath: string;
optimizeFonts: FontConfig;
images: ImageConfigComplete;
fontManifest?: FontManifest;
disableOptimizedLoading?: boolean;
optimizeCss: any;
nextConfigOutput: 'standalone' | 'export';
nextScriptWorkers: any;
locale?: string;
locales?: string[];
defaultLocale?: string;
domainLocales?: DomainLocale[];
distDir: string;
runtime?: ServerRuntime;
serverComponents?: boolean;
crossOrigin?: 'anonymous' | 'use-credentials' | '' | undefined;
supportsDynamicHTML?: boolean;
isBot?: boolean;
clientReferenceManifest?: ClientReferenceManifest;
serverActionsBodySizeLimit?: SizeLimit;
serverActionsManifest?: any;
nextFontManifest?: NextFontManifest;
renderServerComponentData?: boolean;
serverComponentProps?: any;
largePageDataBytes?: number;
appDirDevErrorLogger?: (err: any) => Promise;
strictNextHead: boolean;
isExperimentalCompile?: boolean;
};
export interface BaseRequestHandler {
(req: BaseNextRequest, res: BaseNextResponse, parsedUrl?: NextUrlWithParsedQuery | undefined): Promise;
}
export type RequestContext = {
req: BaseNextRequest;
res: BaseNextResponse;
pathname: string;
query: NextParsedUrlQuery;
renderOpts: RenderOpts;
};
export type FallbackMode = false | undefined | 'blocking' | 'static';
export declare class NoFallbackError extends Error {
}
export declare class WrappedBuildError extends Error {
innerError: Error;
constructor(innerError: Error);
}
type ResponsePayload = {
type: 'html' | 'json' | 'rsc';
body: RenderResult;
revalidateOptions?: any;
};
export default abstract class Server {
readonly hostname?: string;
readonly fetchHostname?: string;
readonly port?: number;
protected readonly dir: string;
protected readonly quiet: boolean;
protected readonly nextConfig: NextConfigComplete;
protected readonly distDir: string;
protected readonly publicDir: string;
protected readonly hasStaticDir: boolean;
protected readonly hasAppDir: boolean;
protected readonly pagesManifest?: PagesManifest;
protected readonly appPathsManifest?: PagesManifest;
protected readonly buildId: string;
protected readonly minimalMode: boolean;
protected readonly renderOpts: BaseRenderOpts;
protected readonly serverOptions: Readonly;
protected readonly appPathRoutes?: Record;
protected readonly clientReferenceManifest?: ClientReferenceManifest;
protected nextFontManifest?: NextFontManifest;
private readonly responseCache;
protected abstract getPublicDir(): string;
protected abstract getHasStaticDir(): boolean;
protected abstract getHasAppDir(dev: boolean): boolean;
protected abstract getPagesManifest(): PagesManifest | undefined;
protected abstract getAppPathsManifest(): PagesManifest | undefined;
protected abstract getBuildId(): string;
protected abstract findPageComponents(params: {
page: string;
query: NextParsedUrlQuery;
params: Params;
isAppPath: boolean;
sriEnabled?: boolean;
appPaths?: ReadonlyArray | null;
shouldEnsure?: boolean;
}): Promise;
protected abstract getFontManifest(): FontManifest | undefined;
protected abstract getPrerenderManifest(): PrerenderManifest;
protected abstract getNextFontManifest(): NextFontManifest | undefined;
protected abstract attachRequestMeta(req: BaseNextRequest, parsedUrl: NextUrlWithParsedQuery): void;
protected abstract getFallback(page: string): Promise;
protected abstract hasPage(pathname: string): Promise;
protected abstract sendRenderResult(req: BaseNextRequest, res: BaseNextResponse, options: {
result: RenderResult;
type: 'html' | 'json' | 'rsc';
generateEtags: boolean;
poweredByHeader: boolean;
options?: PayloadOptions;
}): Promise;
protected abstract runApi(req: BaseNextRequest, res: BaseNextResponse, query: ParsedUrlQuery, match: PagesAPIRouteMatch): Promise;
protected abstract renderHTML(req: BaseNextRequest, res: BaseNextResponse, pathname: string, query: NextParsedUrlQuery, renderOpts: LoadedRenderOpts): Promise;
protected abstract getPrefetchRsc(pathname: string): Promise;
protected abstract getIncrementalCache(options: {
requestHeaders: Record;
requestProtocol: 'http' | 'https';
}): import('./lib/incremental-cache').IncrementalCache;
protected abstract getResponseCache(options: {
dev: boolean;
}): ResponseCacheBase;
protected abstract loadEnvConfig(params: {
dev: boolean;
forceReload?: boolean;
}): void;
readonly matchers: RouteMatcherManager;
protected readonly i18nProvider?: I18NProvider;
protected readonly localeNormalizer?: LocaleRouteNormalizer;
constructor(options: ServerOptions);
protected reloadMatchers(): Promise;
protected handleNextDataRequest(req: BaseNextRequest, res: BaseNextResponse, parsedUrl: NextUrlWithParsedQuery): Promise<{
finished: boolean;
}>;
protected handleNextImageRequest(_req: BaseNextRequest, _res: BaseNextResponse, _parsedUrl: NextUrlWithParsedQuery): Promise<{
finished: boolean;
}>;
protected handleCatchallRenderRequest(_req: BaseNextRequest, _res: BaseNextResponse, _parsedUrl: NextUrlWithParsedQuery): Promise<{
finished: boolean;
}>;
protected handleCatchallMiddlewareRequest(_req: BaseNextRequest, _res: BaseNextResponse, _parsedUrl: NextUrlWithParsedQuery): Promise<{
finished: boolean;
}>;
protected getRouteMatchers(): RouteMatcherManager;
logError(err: Error): void;
handleRequest(req: BaseNextRequest, res: BaseNextResponse, parsedUrl?: NextUrlWithParsedQuery): Promise;
private handleRequestImpl;
getRequestHandler(): BaseRequestHandler;
protected abstract handleUpgrade(req: BaseNextRequest, socket: any, head?: any): Promise;
setAssetPrefix(prefix?: string): void;
protected prepared: boolean;
protected preparedPromise: Promise | null;
/**
* Runs async initialization of server.
* It is idempotent, won't fire underlying initialization more than once.
*/
prepare(): Promise;
protected prepareImpl(): Promise;
protected close(): Promise;
protected getAppPathRoutes(): Record;
protected run(req: BaseNextRequest, res: BaseNextResponse, parsedUrl: UrlWithParsedQuery): Promise;
private runImpl;
private pipe;
private pipeImpl;
private getStaticHTML;
render(req: BaseNextRequest, res: BaseNextResponse, pathname: string, query?: NextParsedUrlQuery, parsedUrl?: NextUrlWithParsedQuery, internalRender?: boolean): Promise;
private renderImpl;
protected getStaticPaths({ pathname, }: {
pathname: string;
requestHeaders: import('./lib/incremental-cache').IncrementalCache['requestHeaders'];
page: string;
isAppPath: boolean;
}): Promise<{
staticPaths?: string[];
fallbackMode?: 'static' | 'blocking' | false;
}>;
private renderToResponseWithComponents;
protected stripInternalHeaders(req: BaseNextRequest): void;
private renderToResponseWithComponentsImpl;
private stripNextDataPath;
protected getOriginalAppPaths(route: string): string[] | null;
protected renderPageComponent(ctx: RequestContext, bubbleNoFallback: boolean): Promise;
private renderToResponse;
protected abstract getMiddleware(): MiddlewareRoutingItem | undefined;
protected abstract getFallbackErrorComponents(): Promise;
protected abstract getRoutesManifest(): NormalizedRouteManifest | undefined;
private renderToResponseImpl;
renderToHTML(req: BaseNextRequest, res: BaseNextResponse, pathname: string, query?: ParsedUrlQuery): Promise;
private renderToHTMLImpl;
renderError(err: Error | null, req: BaseNextRequest, res: BaseNextResponse, pathname: string, query?: NextParsedUrlQuery, setHeaders?: boolean): Promise;
private renderErrorImpl;
private customErrorNo404Warn;
private renderErrorToResponse;
protected renderErrorToResponseImpl(ctx: RequestContext, err: Error | null): Promise;
renderErrorToHTML(err: Error | null, req: BaseNextRequest, res: BaseNextResponse, pathname: string, query?: ParsedUrlQuery): Promise;
render404(req: BaseNextRequest, res: BaseNextResponse, parsedUrl?: Pick, setHeaders?: boolean): Promise;
}
export {};