1 |
|
2 | import { IncomingMessage, ServerResponse } from 'http';
|
3 | import { ParsedUrlQuery } from 'querystring';
|
4 | import { UrlWithParsedQuery } from 'url';
|
5 | import { PrerenderManifest } from '../../build';
|
6 | import { CustomRoutes } from '../../lib/load-custom-routes';
|
7 | import { getRouteMatcher } from '../lib/router/utils';
|
8 | import { __ApiPreviewProps } from './api-utils';
|
9 | import { DomainLocales, NextConfig } from './config';
|
10 | import Router, { DynamicRoutes, PageChecker, Params, Route } from './router';
|
11 | import './node-polyfill-fetch';
|
12 | import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin';
|
13 | import { FontManifest } from './font-utils';
|
14 | declare type DynamicRouteItem = {
|
15 | page: string;
|
16 | match: ReturnType<typeof getRouteMatcher>;
|
17 | };
|
18 | export declare type ServerConstructor = {
|
19 | |
20 |
|
21 |
|
22 | dir?: string;
|
23 | |
24 |
|
25 |
|
26 | quiet?: boolean;
|
27 | |
28 |
|
29 |
|
30 | conf?: NextConfig | null;
|
31 | dev?: boolean;
|
32 | customServer?: boolean;
|
33 | };
|
34 | export default class Server {
|
35 | protected dir: string;
|
36 | protected quiet: boolean;
|
37 | protected nextConfig: NextConfig;
|
38 | protected distDir: string;
|
39 | protected pagesDir?: string;
|
40 | protected publicDir: string;
|
41 | protected hasStaticDir: boolean;
|
42 | protected serverBuildDir: string;
|
43 | protected pagesManifest?: PagesManifest;
|
44 | protected buildId: string;
|
45 | protected minimalMode: boolean;
|
46 | protected renderOpts: {
|
47 | poweredByHeader: boolean;
|
48 | buildId: string;
|
49 | generateEtags: boolean;
|
50 | runtimeConfig?: {
|
51 | [key: string]: any;
|
52 | };
|
53 | assetPrefix?: string;
|
54 | canonicalBase: string;
|
55 | dev?: boolean;
|
56 | previewProps: __ApiPreviewProps;
|
57 | customServer?: boolean;
|
58 | ampOptimizerConfig?: {
|
59 | [key: string]: any;
|
60 | };
|
61 | basePath: string;
|
62 | optimizeFonts: boolean;
|
63 | images: string;
|
64 | fontManifest: FontManifest;
|
65 | optimizeImages: boolean;
|
66 | disableOptimizedLoading?: boolean;
|
67 | optimizeCss: any;
|
68 | locale?: string;
|
69 | locales?: string[];
|
70 | defaultLocale?: string;
|
71 | domainLocales?: DomainLocales;
|
72 | distDir: string;
|
73 | };
|
74 | private compression?;
|
75 | private incrementalCache;
|
76 | protected router: Router;
|
77 | protected dynamicRoutes?: DynamicRoutes;
|
78 | protected customRoutes: CustomRoutes;
|
79 | constructor({ dir, quiet, conf, dev, minimalMode, customServer, }: ServerConstructor & {
|
80 | conf: NextConfig;
|
81 | minimalMode?: boolean;
|
82 | });
|
83 | logError(err: Error): void;
|
84 | private handleRequest;
|
85 | getRequestHandler(): (req: IncomingMessage, res: ServerResponse, parsedUrl?: UrlWithParsedQuery | undefined) => Promise<void>;
|
86 | setAssetPrefix(prefix?: string): void;
|
87 | prepare(): Promise<void>;
|
88 | protected close(): Promise<void>;
|
89 | protected setImmutableAssetCacheControl(res: ServerResponse): void;
|
90 | protected getCustomRoutes(): CustomRoutes;
|
91 | private _cachedPreviewManifest;
|
92 | protected getPrerenderManifest(): PrerenderManifest;
|
93 | protected getPreviewProps(): __ApiPreviewProps;
|
94 | protected generateRoutes(): {
|
95 | basePath: string;
|
96 | headers: Route[];
|
97 | rewrites: {
|
98 | beforeFiles: Route[];
|
99 | afterFiles: Route[];
|
100 | fallback: Route[];
|
101 | };
|
102 | fsRoutes: Route[];
|
103 | redirects: Route[];
|
104 | catchAllRoute: Route;
|
105 | pageChecker: PageChecker;
|
106 | useFileSystemPublicRoutes: boolean;
|
107 | dynamicRoutes: DynamicRoutes | undefined;
|
108 | locales: string[];
|
109 | };
|
110 | private getPagePath;
|
111 | protected hasPage(pathname: string): Promise<boolean>;
|
112 | protected _beforeCatchAllRender(_req: IncomingMessage, _res: ServerResponse, _params: Params, _parsedUrl: UrlWithParsedQuery): Promise<boolean>;
|
113 | protected ensureApiPage(_pathname: string): Promise<void>;
|
114 | |
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | private handleApiRequest;
|
121 | protected generatePublicRoutes(): Route[];
|
122 | protected getDynamicRoutes(): Array<DynamicRouteItem>;
|
123 | private handleCompression;
|
124 | protected run(req: IncomingMessage, res: ServerResponse, parsedUrl: UrlWithParsedQuery): Promise<void>;
|
125 | protected sendHTML(req: IncomingMessage, res: ServerResponse, html: string): Promise<void>;
|
126 | render(req: IncomingMessage, res: ServerResponse, pathname: string, query?: ParsedUrlQuery, parsedUrl?: UrlWithParsedQuery): Promise<void>;
|
127 | private findPageComponents;
|
128 | protected getStaticPaths(pathname: string): Promise<{
|
129 | staticPaths: string[] | undefined;
|
130 | fallbackMode: 'static' | 'blocking' | false;
|
131 | }>;
|
132 | private renderToHTMLWithComponents;
|
133 | renderToHTML(req: IncomingMessage, res: ServerResponse, pathname: string, query?: ParsedUrlQuery): Promise<string | null>;
|
134 | renderError(err: Error | null, req: IncomingMessage, res: ServerResponse, pathname: string, query?: ParsedUrlQuery, setHeaders?: boolean): Promise<void>;
|
135 | private customErrorNo404Warn;
|
136 | renderErrorToHTML(err: Error | null, req: IncomingMessage, res: ServerResponse, _pathname: string, query?: ParsedUrlQuery): Promise<string | null>;
|
137 | render404(req: IncomingMessage, res: ServerResponse, parsedUrl?: UrlWithParsedQuery, setHeaders?: boolean): Promise<void>;
|
138 | serveStatic(req: IncomingMessage, res: ServerResponse, path: string, parsedUrl?: UrlWithParsedQuery): Promise<void>;
|
139 | private _validFilesystemPathSet;
|
140 | private getFilesystemPaths;
|
141 | protected isServeableUrl(untrustedFileUrl: string): boolean;
|
142 | protected readBuildId(): string;
|
143 | protected get _isLikeServerless(): boolean;
|
144 | }
|
145 | export {};
|