Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decouple the public API for custom servers from internals #73021

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 66 additions & 20 deletions packages/next/src/server/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import type { UrlWithParsedQuery } from 'url'
import type { IncomingMessage, ServerResponse } from 'http'
import type { Duplex } from 'stream'
import type { NextUrlWithParsedQuery } from './request-meta'
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta'
import type { ParsedUrlQuery } from 'querystring'
import type { WorkerRequestHandler, WorkerUpgradeHandler } from './lib/types'

Check failure on line 11 in packages/next/src/server/next.ts

View workflow job for this annotation

GitHub Actions / lint / build

'WorkerRequestHandler' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 11 in packages/next/src/server/next.ts

View workflow job for this annotation

GitHub Actions / lint / build

'WorkerUpgradeHandler' is defined but never used. Allowed unused vars must match /^_/u

import './require-hook'
import './node-polyfill-crypto'
Expand Down Expand Up @@ -57,7 +59,7 @@

const SYMBOL_LOAD_CONFIG = Symbol('next.load_config')

interface NextWrapperServer {
interface NextWrapperServer extends LegacyServerMethods {
// NOTE: the methods/properties here are the public API for custom servers.
// Consider backwards compatibilty when changing something here!

Expand All @@ -72,30 +74,74 @@

// used internally
getUpgradeHandler(): UpgradeHandler
}

// legacy methods that we left exposed in the past

logError(...args: Parameters<NextNodeServer['logError']>): void

interface LegacyServerMethods {
/**
* This method is only public for backwards compatibility, and may change or be removed in a future release.
* @deprecated
*/
logError(err: Error): void

/**
* This method is only public for backwards compatibility, and may change or be removed in a future release.
* @deprecated
*/
render(
...args: Parameters<NextNodeServer['render']>
): ReturnType<NextNodeServer['render']>

req: IncomingMessage,
res: ServerResponse,
pathname: string,
query?: NextParsedUrlQuery,
parsedUrl?: NextUrlWithParsedQuery,
internal?: boolean
): Promise<void>

/**
* This method is only public for backwards compatibility, and may change or be removed in a future release.
* @deprecated
*/
renderToHTML(
...args: Parameters<NextNodeServer['renderToHTML']>
): ReturnType<NextNodeServer['renderToHTML']>

req: IncomingMessage,
res: ServerResponse,
pathname: string,
query?: ParsedUrlQuery
): Promise<string | null>

/**
* This method is only public for backwards compatibility, and may change or be removed in a future release.
* @deprecated
*/
renderError(
...args: Parameters<NextNodeServer['renderError']>
): ReturnType<NextNodeServer['renderError']>

err: Error | null,
req: IncomingMessage,
res: ServerResponse,
pathname: string,
query?: NextParsedUrlQuery,
setHeaders?: boolean
): Promise<void>

/**
* This method is only public for backwards compatibility, and may change or be removed in a future release.
* @deprecated
*/
renderErrorToHTML(
...args: Parameters<NextNodeServer['renderErrorToHTML']>
): ReturnType<NextNodeServer['renderErrorToHTML']>

err: Error | null,
req: IncomingMessage,
res: ServerResponse,
pathname: string,
query?: ParsedUrlQuery
): Promise<string | null>

/**
* This method is only public for backwards compatibility, and may change or be removed in a future release.
* @deprecated
*/
render404(
...args: Parameters<NextNodeServer['render404']>
): ReturnType<NextNodeServer['render404']>
req: IncomingMessage,
res: ServerResponse,
parsedUrl?: NextUrlWithParsedQuery,
setHeaders?: boolean
): Promise<void>
}

/** The wrapper server used by `next start` */
Expand Down
Loading