Skip to content

Commit

Permalink
separate public interface from internal BaseServer types
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Nov 21, 2024
1 parent 0d11d04 commit ae1992f
Showing 1 changed file with 65 additions and 20 deletions.
85 changes: 65 additions & 20 deletions packages/next/src/server/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
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 { WorkerRequestHandler, WorkerUpgradeHandler } from './lib/types'

import './require-hook'
Expand All @@ -26,6 +26,7 @@ import { getTracer } from './lib/trace/tracer'
import { NextServerSpan } from './lib/trace/constants'
import { formatUrl } from '../shared/lib/router/utils/format-url'
import type { ServerFields } from './lib/router-utils/setup-dev-bundler'
import type { ParsedUrlQuery } from 'querystring'

let ServerImpl: typeof NextNodeServer

Expand Down Expand Up @@ -57,7 +58,7 @@ export type UpgradeHandler = (

const SYMBOL_LOAD_CONFIG = Symbol('next.load_config')

export interface NextWrapperServer {
export 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 +73,74 @@ export interface NextWrapperServer {

// 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

0 comments on commit ae1992f

Please sign in to comment.