Skip to content

Commit

Permalink
Reorder sections of useHttpServer function
Browse files Browse the repository at this point in the history
  • Loading branch information
apteryxxyz committed Nov 5, 2023
1 parent ece070a commit 3571c27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/server/utilities/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)) {
Expand Down

0 comments on commit 3571c27

Please sign in to comment.