Skip to content

Commit

Permalink
remove inheritance from NextCustomServer
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Nov 20, 2024
1 parent f803a95 commit dab5440
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 81 deletions.
37 changes: 12 additions & 25 deletions packages/next/src/server/lib/render-server.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import type { NextServer, RequestHandler } from '../next'
import type { NextServer, RequestHandler, UpgradeHandler } from '../next'
import type { DevBundlerService } from './dev-bundler-service'
import type { PropagateToWorkersField } from './router-utils/types'

import next from '../next'
import type { Span } from '../../trace'

let initializations: Record<
string,
| Promise<{
requestHandler: ReturnType<
InstanceType<typeof NextServer>['getRequestHandler']
>
upgradeHandler: ReturnType<
InstanceType<typeof NextServer>['getUpgradeHandler']
>
app: ReturnType<typeof next>
}>
| undefined
> = {}
type InitializationResult = {
requestHandler: RequestHandler
upgradeHandler: UpgradeHandler
app: NextServer
}

let initializations: Record<string, Promise<InitializationResult> | undefined> =
{}

let sandboxContext: undefined | typeof import('../web/sandbox/context')

Expand Down Expand Up @@ -93,15 +88,15 @@ async function initializeImpl(opts: {
}

let requestHandler: RequestHandler
let upgradeHandler: any
let upgradeHandler: UpgradeHandler

const app = next({
...opts,
hostname: opts.hostname || 'localhost',
customServer: false,
httpServer: opts.server,
port: opts.port,
})
}) as NextServer // should return a NextServer when `customServer: false`
requestHandler = app.getRequestHandler()
upgradeHandler = app.getUpgradeHandler()

Expand All @@ -116,15 +111,7 @@ async function initializeImpl(opts: {

export async function initialize(
opts: Parameters<typeof initializeImpl>[0]
): Promise<{
requestHandler: ReturnType<
InstanceType<typeof NextServer>['getRequestHandler']
>
upgradeHandler: ReturnType<
InstanceType<typeof NextServer>['getUpgradeHandler']
>
app: NextServer
}> {
): Promise<InitializationResult> {
// if we already setup the server return as we only need to do
// this on first worker boot
if (initializations[opts.dir]) {
Expand Down
Loading

0 comments on commit dab5440

Please sign in to comment.