next-ws 1.0.1-canary.1 → 1.0.1-experimental.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import { Server } from 'node:http';
|
|
3
3
|
import NextNodeServer from 'next/dist/server/next-server';
|
|
4
4
|
import { WebSocketServer } from 'ws';
|
|
5
|
-
export declare const CustomHttpServer
|
|
5
|
+
export declare const CustomHttpServer = "NextWS::CustomHttpServer";
|
|
6
6
|
/**
|
|
7
7
|
* Get the HTTP Server instance from the NextNodeServer.
|
|
8
8
|
* @param nextServer The NextNodeServer instance.
|
|
9
9
|
* @returns The HTTP Server instance.
|
|
10
10
|
*/
|
|
11
11
|
export declare function useHttpServer(nextServer: NextNodeServer): Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
12
|
-
export declare const CustomWsServer
|
|
12
|
+
export declare const CustomWsServer = "NextWS::CustomWsServer";
|
|
13
13
|
/**
|
|
14
14
|
* Create a WebSocketServer.
|
|
15
15
|
* @returns The WebSocketServer instance.
|
|
@@ -7,22 +7,23 @@ const Log = tslib_1.__importStar(require("next/dist/build/output/log"));
|
|
|
7
7
|
const next_server_1 = tslib_1.__importDefault(require("next/dist/server/next-server"));
|
|
8
8
|
const ws_1 = require("ws");
|
|
9
9
|
// =============== HTTP Server ===============
|
|
10
|
-
exports.CustomHttpServer =
|
|
10
|
+
exports.CustomHttpServer = 'NextWS::CustomHttpServer';
|
|
11
11
|
/**
|
|
12
12
|
* Get the HTTP Server instance from the NextNodeServer.
|
|
13
13
|
* @param nextServer The NextNodeServer instance.
|
|
14
14
|
* @returns The HTTP Server instance.
|
|
15
15
|
*/
|
|
16
16
|
function useHttpServer(nextServer) {
|
|
17
|
+
// NextNodeServer is always required, so check for it before attempting to use custom server
|
|
18
|
+
if (!nextServer || !(nextServer instanceof next_server_1.default)) {
|
|
19
|
+
Log.error('[next-ws] could not find the NextNodeServer instance');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
17
22
|
const existing = Reflect.get(globalThis, exports.CustomHttpServer);
|
|
18
23
|
if (existing) {
|
|
19
24
|
Log.warnOnce('[next-ws] is using a custom HTTP Server, this is experimental and may not work as expected');
|
|
20
25
|
return existing;
|
|
21
26
|
}
|
|
22
|
-
if (!nextServer || !(nextServer instanceof next_server_1.default)) {
|
|
23
|
-
Log.error('[next-ws] could not find the NextNodeServer instance');
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
27
|
// @ts-expect-error - serverOptions is protected
|
|
27
28
|
const httpServer = nextServer.serverOptions?.httpServer;
|
|
28
29
|
if (!httpServer || !(httpServer instanceof node_http_1.Server)) {
|
|
@@ -33,7 +34,7 @@ function useHttpServer(nextServer) {
|
|
|
33
34
|
}
|
|
34
35
|
exports.useHttpServer = useHttpServer;
|
|
35
36
|
// =============== WebSocket Server ===============
|
|
36
|
-
exports.CustomWsServer =
|
|
37
|
+
exports.CustomWsServer = 'NextWS::CustomWsServer';
|
|
37
38
|
/**
|
|
38
39
|
* Create a WebSocketServer.
|
|
39
40
|
* @returns The WebSocketServer instance.
|