From 8fc880008806728df7eb10b42a4c81bd2322a93a Mon Sep 17 00:00:00 2001 From: Geoffrey <11151445+g3offrey@users.noreply.github.com> Date: Thu, 21 Oct 2021 00:19:39 +0200 Subject: [PATCH] Add support for async `experimental.initServer()` (#2798) Co-authored-by: Brandon Bayer (minor) --- nextjs/packages/next/server/next-server.ts | 5 ----- nextjs/packages/next/server/next.ts | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nextjs/packages/next/server/next-server.ts b/nextjs/packages/next/server/next-server.ts index a515279ee7..3580e16a8d 100644 --- a/nextjs/packages/next/server/next-server.ts +++ b/nextjs/packages/next/server/next-server.ts @@ -217,7 +217,6 @@ export default class Server { assetPrefix, generateEtags, compress, - experimental, } = this.nextConfig this.buildId = this.readBuildId() @@ -277,10 +276,6 @@ export default class Server { this.router = new Router(this.generateRoutes()) this.setAssetPrefix(assetPrefix) - if (experimental.initServer) { - experimental.initServer() - } - this.incrementalCache = new IncrementalCache({ dev, distDir: this.distDir, diff --git a/nextjs/packages/next/server/next.ts b/nextjs/packages/next/server/next.ts index fb048331d5..76aba7bc26 100644 --- a/nextjs/packages/next/server/next.ts +++ b/nextjs/packages/next/server/next.ts @@ -130,6 +130,11 @@ export class NextServer { if (!this.serverPromise) { setTimeout(getServerImpl, 10) this.serverPromise = this.loadConfig().then(async (conf) => { + const initServerCallback = conf.experimental.initServer + if (initServerCallback) { + await initServerCallback() + } + this.server = await this.createServer({ ...this.options, conf,