From 96532db3aa783e332a391d8546dd7bb58c44db0c Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 7 Aug 2023 13:03:26 +0200 Subject: [PATCH] Remove shouldUseStandaloneMode variable --- packages/next/src/server/next.ts | 62 +++++++++++--------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/packages/next/src/server/next.ts b/packages/next/src/server/next.ts index e84075488a3a3..5222f5ab9476b 100644 --- a/packages/next/src/server/next.ts +++ b/packages/next/src/server/next.ts @@ -50,7 +50,6 @@ export interface RequestHandler { ): Promise } -const SYMBOL_SET_STANDALONE_MODE = Symbol('next.set_standalone_mode') const SYMBOL_LOAD_CONFIG = Symbol('next.load_config') export class NextServer { @@ -76,10 +75,6 @@ export class NextServer { return this.options.port } - [SYMBOL_SET_STANDALONE_MODE]() { - this.standaloneMode = true - } - getRequestHandler(): RequestHandler { return async ( req: IncomingMessage, @@ -270,10 +265,6 @@ function createServer(options: NextServerOptions): NextServer { } if (options.customServer !== false) { - // If the `app` dir exists, we'll need to run the standalone server to have - // both types of renderers (pages, app) running in separated processes, - // instead of having the Next server only. - let shouldUseStandaloneMode = false const dir = resolve(options.dir || '.') const server = new NextServer(options) @@ -300,9 +291,7 @@ function createServer(options: NextServerOptions): NextServer { ) } else { customServer.on('upgrade', async (req, socket, head) => { - if (shouldUseStandaloneMode) { - upgradeHandler(req, socket, head) - } + upgradeHandler(req, socket, head) }) } } @@ -314,8 +303,6 @@ function createServer(options: NextServerOptions): NextServer { switch (propKey) { case 'prepare': return async () => { - shouldUseStandaloneMode = true - server[SYMBOL_SET_STANDALONE_MODE]() const isNodeDebugging = checkIsNodeDebugging() const initResult = await getRequestHandlers({ @@ -331,24 +318,19 @@ function createServer(options: NextServerOptions): NextServer { } case 'getRequestHandler': { return () => { - let handler: RequestHandler return async ( req: IncomingMessage, res: ServerResponse, parsedUrl?: UrlWithParsedQuery ) => { - if (shouldUseStandaloneMode) { - setupWebSocketHandler(options.httpServer, req) - - if (parsedUrl) { - req.url = formatUrl(parsedUrl) - } + setupWebSocketHandler(options.httpServer, req) - requestHandler(req, res) - return + if (parsedUrl) { + req.url = formatUrl(parsedUrl) } - handler = handler || server.getRequestHandler() - return handler(req, res, parsedUrl) + + requestHandler(req, res) + return } } } @@ -360,26 +342,22 @@ function createServer(options: NextServerOptions): NextServer { query?: NextParsedUrlQuery, parsedUrl?: NextUrlWithParsedQuery ) => { - if (shouldUseStandaloneMode) { - setupWebSocketHandler(options.httpServer, req) - - if (!pathname.startsWith('/')) { - console.error(`Cannot render page with path "${pathname}"`) - pathname = `/${pathname}` - } - pathname = pathname === '/index' ? '/' : pathname - - req.url = formatUrl({ - ...parsedUrl, - pathname, - query, - }) + setupWebSocketHandler(options.httpServer, req) - requestHandler(req, res) - return + if (!pathname.startsWith('/')) { + console.error(`Cannot render page with path "${pathname}"`) + pathname = `/${pathname}` } + pathname = pathname === '/index' ? '/' : pathname + + req.url = formatUrl({ + ...parsedUrl, + pathname, + query, + }) - return server.render(req, res, pathname, query, parsedUrl) + requestHandler(req, res) + return } } default: {