@dangao/bun-server 3.0.3 → 3.0.4
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/dist/index.js +4 -1
- package/dist/index.node.mjs +4 -1
- package/package.json +1 -1
- package/src/platform/node/http.ts +13 -2
package/dist/index.js
CHANGED
|
@@ -12704,7 +12704,10 @@ function setupWebSocket(httpServer, handlers) {
|
|
|
12704
12704
|
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
12705
12705
|
` + "Install it with: bun add ws");
|
|
12706
12706
|
}
|
|
12707
|
-
const
|
|
12707
|
+
const WebSocketServer = wsModule.WebSocketServer ?? wsModule.default?.WebSocketServer ?? wsModule.Server;
|
|
12708
|
+
if (!WebSocketServer) {
|
|
12709
|
+
throw new Error("[bun-server] Could not find WebSocketServer in the ws module. " + "Please ensure ws >= 7.5.0 is installed.");
|
|
12710
|
+
}
|
|
12708
12711
|
const wss = new WebSocketServer({ noServer: true });
|
|
12709
12712
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
12710
12713
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
package/dist/index.node.mjs
CHANGED
|
@@ -665,7 +665,10 @@ function setupWebSocket(httpServer, handlers) {
|
|
|
665
665
|
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
666
666
|
` + "Install it with: bun add ws");
|
|
667
667
|
}
|
|
668
|
-
const
|
|
668
|
+
const WebSocketServer = wsModule.WebSocketServer ?? wsModule.default?.WebSocketServer ?? wsModule.Server;
|
|
669
|
+
if (!WebSocketServer) {
|
|
670
|
+
throw new Error("[bun-server] Could not find WebSocketServer in the ws module. " + "Please ensure ws >= 7.5.0 is installed.");
|
|
671
|
+
}
|
|
669
672
|
const wss = new WebSocketServer({ noServer: true });
|
|
670
673
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
671
674
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
package/package.json
CHANGED
|
@@ -178,8 +178,19 @@ function setupWebSocket<T>(
|
|
|
178
178
|
'Install it with: bun add ws',
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
// Handle CJS (WebSocketServer as class property) and ESM interop (named export)
|
|
182
|
+
// Also falls back to .Server for ws < 7.5.0
|
|
183
|
+
const WebSocketServer =
|
|
184
|
+
(wsModule as unknown as Record<string, unknown>).WebSocketServer ??
|
|
185
|
+
(wsModule as unknown as { default?: Record<string, unknown> }).default?.WebSocketServer ??
|
|
186
|
+
(wsModule as unknown as Record<string, unknown>).Server;
|
|
187
|
+
if (!WebSocketServer) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
'[bun-server] Could not find WebSocketServer in the ws module. ' +
|
|
190
|
+
'Please ensure ws >= 7.5.0 is installed.',
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
const wss = new (WebSocketServer as new (opts: unknown) => import('ws').WebSocketServer)({ noServer: true });
|
|
183
194
|
|
|
184
195
|
httpServer.on('upgrade', (request, socket, head) => {
|
|
185
196
|
wss.handleUpgrade(request, socket, head, (ws) => {
|