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 22, 2024
1 parent ed871e1 commit 063150f
Showing 1 changed file with 66 additions and 20 deletions.
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 {
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 @@ export type UpgradeHandler = (

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 @@ 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 063150f

Please sign in to comment.