diff --git a/packages/core/package.json b/packages/core/package.json index 7eb1830..d3290ee 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "next-ws", - "version": "1.0.1-canary.1", + "version": "1.0.1-experimental.1", "description": "Add support for WebSockets in Next.js 13 app directory", "keywords": [ "next", diff --git a/packages/core/src/server/utilities/server.ts b/packages/core/src/server/utilities/server.ts index d056911..598e442 100644 --- a/packages/core/src/server/utilities/server.ts +++ b/packages/core/src/server/utilities/server.ts @@ -13,6 +13,12 @@ export const CustomHttpServer = Symbol('NextWS::CustomHttpServer'); * @returns The HTTP Server instance. */ export function useHttpServer(nextServer: NextNodeServer) { + // NextNodeServer is always required, so check for it before attempting to use custom server + if (!nextServer || !(nextServer instanceof NextNodeServer)) { + Log.error('[next-ws] could not find the NextNodeServer instance'); + process.exit(1); + } + const existing = Reflect.get(globalThis, CustomHttpServer) as Server; if (existing) { Log.warnOnce( @@ -21,11 +27,6 @@ export function useHttpServer(nextServer: NextNodeServer) { return existing; } - if (!nextServer || !(nextServer instanceof NextNodeServer)) { - Log.error('[next-ws] could not find the NextNodeServer instance'); - process.exit(1); - } - // @ts-expect-error - serverOptions is protected const httpServer = nextServer.serverOptions?.httpServer; if (!httpServer || !(httpServer instanceof Server)) {