Add server properties.

This commit is contained in:
João Vieira
2018-08-23 16:59:54 +01:00
parent 812734a111
commit f56a12fc88

93
types/next/index.d.ts vendored
View File

@@ -16,13 +16,16 @@ import * as url from "url";
import { Response as NodeResponse } from "node-fetch";
import Router from './router';
declare namespace next {
/** Map object used in query strings. */
type QueryStringMapObject = Record<string, string | string[] | undefined>;
/**
* Context object used in methods like `getInitialProps()`
* <<https://github.com/zeit/next.js/issues/1651>>
* https://github.com/zeit/next.js/blob/6.1.1/server/render.js#L77
* https://github.com/zeit/next.js/blob/6.1.1/readme.md#fetching-data-and-component-lifecycle
*/
interface NextContext {
/** path section of URL */
@@ -39,8 +42,6 @@ declare namespace next {
jsonPageRes?: NodeResponse;
/** Error object if any error is encountered during the rendering */
err?: Error;
/** Whether we're running on the server environment or not. */
isServer?: boolean;
}
type NextSFC<TProps = {}> = NextStatelessComponent<TProps>;
@@ -51,8 +52,11 @@ declare namespace next {
type UrlLike = url.UrlObject | url.Url;
interface ServerConfig {
// known keys
/**
* Next.js config schema.
* https://github.com/zeit/next.js/blob/6.1.1/server/config.js#L10
*/
interface NextConfig {
webpack?: any;
webpackDevMiddleware?: any;
poweredByHeader?: boolean;
@@ -60,21 +64,58 @@ declare namespace next {
assetPrefix?: string;
configOrigin?: string;
useFileSystemPublicRoutes?: boolean;
generateBuildId?: () => string;
generateEtags?: boolean;
pageExtensions?: string[];
publicRuntimeConfig?: object;
serverRuntimeConfig?: object;
// and since this is a config, it can take anything else, too.
// Plugin can define their own keys.
[key: string]: any;
}
/**
* Options passed to the Server constructor in Node.js.
* https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30
*/
interface ServerOptions {
dir?: string;
dev?: boolean;
staticMarkup?: boolean;
quiet?: boolean;
conf?: ServerConfig;
conf?: NextConfig;
}
/**
* Next.js server instance API.
*/
interface Server {
setAssetPrefix: (cdnUrl: string) => void;
// From constructor
// https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30
dir: string;
dev: boolean;
quiet: boolean;
router: Router;
http: null | http.Server;
nextConfig: NextConfig;
distDir: string;
buildId: string;
hotReloader: any;
renderOpts: {
dev: string;
staticMarkup: boolean;
distDir: string;
hotReloader: any;
buildId: string;
availableChunks: object;
generateETags: boolean;
runtimeConfig?: object;
};
getHotReloader(
dir: string,
options: { quiet: boolean; config: NextConfig; buildId: string }
): any;
handleRequest(
req: http.IncomingMessage,
res: http.ServerResponse,
@@ -85,6 +126,8 @@ declare namespace next {
res: http.ServerResponse,
parsedUrl?: UrlLike
) => Promise<void>;
setAssetPrefix(prefix: string): void;
prepare(): Promise<void>;
close(): Promise<void>;
defineRoutes(): Promise<void>;
@@ -102,6 +145,12 @@ declare namespace next {
query?: QueryStringMapObject,
parsedUrl?: UrlLike
): Promise<void>;
renderToHTML(
req: http.IncomingMessage,
res: http.ServerResponse,
pathname: string,
query?: QueryStringMapObject
): Promise<string>;
renderError(
err: any,
req: http.IncomingMessage,
@@ -109,17 +158,6 @@ declare namespace next {
pathname: string,
query?: QueryStringMapObject
): Promise<void>;
render404(
req: http.IncomingMessage,
res: http.ServerResponse,
parsedUrl: UrlLike
): Promise<void>;
renderToHTML(
req: http.IncomingMessage,
res: http.ServerResponse,
pathname: string,
query?: QueryStringMapObject
): Promise<string>;
renderErrorToHTML(
err: any,
req: http.IncomingMessage,
@@ -127,6 +165,11 @@ declare namespace next {
pathname: string,
query?: QueryStringMapObject
): Promise<string>;
render404(
req: http.IncomingMessage,
res: http.ServerResponse,
parsedUrl?: UrlLike
): Promise<void>;
serveStatic(
req: http.IncomingMessage,
@@ -134,19 +177,9 @@ declare namespace next {
path: string
): Promise<void>;
isServeableUrl(path: string): boolean;
isInternalUrl(req: http.IncomingMessage): boolean;
readBuildId(): string;
handleBuildId(buildId: string, res: http.ServerResponse): boolean;
getCompilationError(
page: string,
req: http.IncomingMessage,
res: http.ServerResponse
): Promise<any>;
handleBuildHash(
filename: string,
hash: string,
res: http.ServerResponse
): void;
getCompilationError(): Promise<any>;
send404(res: http.ServerResponse): void;
}
}