1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | import * as http from "http";
|
15 | import * as url from "url";
|
16 |
|
17 | import { Response as NodeResponse } from "node-fetch";
|
18 |
|
19 | declare namespace next {
|
20 |
|
21 | type QueryStringMapObject = Record<string, string | string[] | undefined>;
|
22 |
|
23 | |
24 |
|
25 |
|
26 |
|
27 | interface NextContext {
|
28 |
|
29 | pathname: string;
|
30 |
|
31 | query: QueryStringMapObject;
|
32 |
|
33 | asPath: string;
|
34 |
|
35 | req?: http.IncomingMessage;
|
36 |
|
37 | res?: http.ServerResponse;
|
38 |
|
39 | jsonPageRes?: NodeResponse;
|
40 |
|
41 | err?: Error;
|
42 |
|
43 | isServer?: boolean;
|
44 | }
|
45 |
|
46 | type NextSFC<TProps = {}> = NextStatelessComponent<TProps>;
|
47 | interface NextStatelessComponent<TProps = {}>
|
48 | extends React.StatelessComponent<TProps> {
|
49 | getInitialProps?: (ctx: NextContext) => Promise<TProps>;
|
50 | }
|
51 |
|
52 | type UrlLike = url.UrlObject | url.Url;
|
53 |
|
54 | interface ServerConfig {
|
55 |
|
56 | webpack?: any;
|
57 | webpackDevMiddleware?: any;
|
58 | poweredByHeader?: boolean;
|
59 | distDir?: string;
|
60 | assetPrefix?: string;
|
61 | configOrigin?: string;
|
62 | useFileSystemPublicRoutes?: boolean;
|
63 |
|
64 |
|
65 | [key: string]: any;
|
66 | }
|
67 |
|
68 | interface ServerOptions {
|
69 | dir?: string;
|
70 | dev?: boolean;
|
71 | staticMarkup?: boolean;
|
72 | quiet?: boolean;
|
73 | conf?: ServerConfig;
|
74 | }
|
75 |
|
76 | interface Server {
|
77 | setAssetPrefix: (cdnUrl: string) => void;
|
78 | handleRequest(
|
79 | req: http.IncomingMessage,
|
80 | res: http.ServerResponse,
|
81 | parsedUrl?: UrlLike
|
82 | ): Promise<void>;
|
83 | getRequestHandler(): (
|
84 | req: http.IncomingMessage,
|
85 | res: http.ServerResponse,
|
86 | parsedUrl?: UrlLike
|
87 | ) => Promise<void>;
|
88 | prepare(): Promise<void>;
|
89 | close(): Promise<void>;
|
90 | defineRoutes(): Promise<void>;
|
91 | start(): Promise<void>;
|
92 | run(
|
93 | req: http.IncomingMessage,
|
94 | res: http.ServerResponse,
|
95 | parsedUrl: UrlLike
|
96 | ): Promise<void>;
|
97 |
|
98 | render(
|
99 | req: http.IncomingMessage,
|
100 | res: http.ServerResponse,
|
101 | pathname: string,
|
102 | query?: QueryStringMapObject,
|
103 | parsedUrl?: UrlLike
|
104 | ): Promise<void>;
|
105 | renderError(
|
106 | err: any,
|
107 | req: http.IncomingMessage,
|
108 | res: http.ServerResponse,
|
109 | pathname: string,
|
110 | query?: QueryStringMapObject
|
111 | ): Promise<void>;
|
112 | render404(
|
113 | req: http.IncomingMessage,
|
114 | res: http.ServerResponse,
|
115 | parsedUrl: UrlLike
|
116 | ): Promise<void>;
|
117 | renderToHTML(
|
118 | req: http.IncomingMessage,
|
119 | res: http.ServerResponse,
|
120 | pathname: string,
|
121 | query?: QueryStringMapObject
|
122 | ): Promise<string>;
|
123 | renderErrorToHTML(
|
124 | err: any,
|
125 | req: http.IncomingMessage,
|
126 | res: http.ServerResponse,
|
127 | pathname: string,
|
128 | query?: QueryStringMapObject
|
129 | ): Promise<string>;
|
130 |
|
131 | serveStatic(
|
132 | req: http.IncomingMessage,
|
133 | res: http.ServerResponse,
|
134 | path: string
|
135 | ): Promise<void>;
|
136 | isServeableUrl(path: string): boolean;
|
137 | isInternalUrl(req: http.IncomingMessage): boolean;
|
138 | readBuildId(): string;
|
139 | handleBuildId(buildId: string, res: http.ServerResponse): boolean;
|
140 | getCompilationError(
|
141 | page: string,
|
142 | req: http.IncomingMessage,
|
143 | res: http.ServerResponse
|
144 | ): Promise<any>;
|
145 | handleBuildHash(
|
146 | filename: string,
|
147 | hash: string,
|
148 | res: http.ServerResponse
|
149 | ): void;
|
150 | send404(res: http.ServerResponse): void;
|
151 | }
|
152 | }
|
153 |
|
154 | declare function next(options?: next.ServerOptions): next.Server;
|
155 | export = next;
|