@dangao/bun-server 3.0.2 → 3.0.3
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 +8 -1
- package/dist/index.node.mjs +8 -1
- package/package.json +7 -4
- package/src/platform/node/http.ts +11 -1
package/dist/index.js
CHANGED
|
@@ -12697,7 +12697,14 @@ function sendWebResponse(res, webResponse) {
|
|
|
12697
12697
|
pump();
|
|
12698
12698
|
}
|
|
12699
12699
|
function setupWebSocket(httpServer, handlers) {
|
|
12700
|
-
|
|
12700
|
+
let wsModule;
|
|
12701
|
+
try {
|
|
12702
|
+
wsModule = __require("ws");
|
|
12703
|
+
} catch {
|
|
12704
|
+
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
12705
|
+
` + "Install it with: bun add ws");
|
|
12706
|
+
}
|
|
12707
|
+
const { WebSocketServer } = wsModule;
|
|
12701
12708
|
const wss = new WebSocketServer({ noServer: true });
|
|
12702
12709
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
12703
12710
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
package/dist/index.node.mjs
CHANGED
|
@@ -658,7 +658,14 @@ function sendWebResponse(res, webResponse) {
|
|
|
658
658
|
pump();
|
|
659
659
|
}
|
|
660
660
|
function setupWebSocket(httpServer, handlers) {
|
|
661
|
-
|
|
661
|
+
let wsModule;
|
|
662
|
+
try {
|
|
663
|
+
wsModule = __require("ws");
|
|
664
|
+
} catch {
|
|
665
|
+
throw new Error(`[bun-server] WebSocket on Node.js requires the ws package.
|
|
666
|
+
` + "Install it with: bun add ws");
|
|
667
|
+
}
|
|
668
|
+
const { WebSocketServer } = wsModule;
|
|
662
669
|
const wss = new WebSocketServer({ noServer: true });
|
|
663
670
|
httpServer.on("upgrade", (request, socket, head) => {
|
|
664
671
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dangao/bun-server",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -66,11 +66,15 @@
|
|
|
66
66
|
"vitest": "^4.1.4"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@vscode/sqlite3": "5.1.12-vscode"
|
|
69
|
+
"@vscode/sqlite3": "5.1.12-vscode",
|
|
70
|
+
"ws": "^8.0.0"
|
|
70
71
|
},
|
|
71
72
|
"peerDependenciesMeta": {
|
|
72
73
|
"@vscode/sqlite3": {
|
|
73
74
|
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"ws": {
|
|
77
|
+
"optional": true
|
|
74
78
|
}
|
|
75
79
|
},
|
|
76
80
|
"dependencies": {
|
|
@@ -82,7 +86,6 @@
|
|
|
82
86
|
"mime-types": "^3.0.2",
|
|
83
87
|
"mysql2": "^3.21.0",
|
|
84
88
|
"postgres": "^3.4.9",
|
|
85
|
-
"reflect-metadata": "^0.2.2"
|
|
86
|
-
"ws": "^8.20.0"
|
|
89
|
+
"reflect-metadata": "^0.2.2"
|
|
87
90
|
}
|
|
88
91
|
}
|
|
@@ -168,7 +168,17 @@ function setupWebSocket<T>(
|
|
|
168
168
|
httpServer: import('node:http').Server,
|
|
169
169
|
handlers: WebSocketHandlers<T>,
|
|
170
170
|
): void {
|
|
171
|
-
|
|
171
|
+
let wsModule: typeof import('ws');
|
|
172
|
+
try {
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
174
|
+
wsModule = require('ws');
|
|
175
|
+
} catch {
|
|
176
|
+
throw new Error(
|
|
177
|
+
'[bun-server] WebSocket on Node.js requires the ws package.\n' +
|
|
178
|
+
'Install it with: bun add ws',
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const { WebSocketServer } = wsModule;
|
|
172
182
|
const wss = new WebSocketServer({ noServer: true });
|
|
173
183
|
|
|
174
184
|
httpServer.on('upgrade', (request, socket, head) => {
|