Skip to content

Commit 206b029

Browse files
committed
fix: websocket fails to initialize
1 parent df61e4e commit 206b029

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

bun.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"workspaces": {
44
"": {
55
"name": "course-mate",
6+
"dependencies": {
7+
"@hono/node-server": "^1.13.8",
8+
},
69
"devDependencies": {
710
"@biomejs/biome": "^1.9.1",
811
"lefthook": "^1.10.10",
@@ -278,6 +281,8 @@
278281

279282
"@grpc/proto-loader": ["@grpc/[email protected]", "", { "dependencies": { "lodash.camelcase": "^4.3.0", "long": "^5.0.0", "protobufjs": "^7.2.5", "yargs": "^17.7.2" }, "bin": { "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" } }, "sha512-AiXO/bfe9bmxBjxxtYxFAXGZvMaN5s8kO+jBHAJCON8rJoB5YS/D6X7ZNc6XQkuHNmyl4CYaMI1fJ/Gn27RGGw=="],
280283

284+
"@hono/node-server": ["@hono/[email protected]", "", { "peerDependencies": { "hono": "^4" } }, "sha512-fsn8ucecsAXUoVxrUil0m13kOEq4mkX4/4QozCqmY+HpGfKl74OYSn8JcMA8GnG0ClfdRI4/ZSeG7zhFaVg+wg=="],
285+
281286
"@hono/zod-validator": ["@hono/[email protected]", "", { "peerDependencies": { "hono": ">=3.9.0", "zod": "^3.19.1" } }, "sha512-xIgMYXDyJ4Hj6ekm9T9Y27s080Nl9NXHcJkOvkXPhubOLj8hZkOL8pDnnXfvCf5xEE8Q4oMFenQUZZREUY2gqQ=="],
282287

283288
"@hookform/resolvers": ["@hookform/[email protected]", "", { "peerDependencies": { "react-hook-form": "^7.0.0" } }, "sha512-79Dv+3mDF7i+2ajj7SkypSKHhl1cbln1OGavqrsF7p6mbUv11xpqpacPsGDCTRvCSjEEIez2ef1NveSVL3b0Ag=="],

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"lefthook": "^1.10.10",
3737
"lint-staged": "^15.2.10"
3838
},
39-
"dependencies": {},
39+
"dependencies": {
40+
"@hono/node-server": "^1.13.8"
41+
},
4042
"trustedDependencies": ["@biomejs/biome", "lefthook"]
4143
}

server/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Server } from "node:http";
21
import { Hono } from "hono";
32
import { cors } from "hono/cors";
43
import { HTTPException } from "hono/http-exception";
@@ -58,7 +57,6 @@ export function main() {
5857
port: process.env.PORT ?? 3000,
5958
});
6059
// ??
61-
initializeSocket(server as unknown as Server, corsOptions);
62-
return server;
60+
return initializeSocket(app, corsOptions);
6361
}
6462
export default app;

server/src/lib/socket/socket.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import type { Server } from "node:http";
1+
import { serve } from "@hono/node-server";
22
import type { Message, UserID } from "common/types";
3-
import type { CorsOptions } from "cors";
3+
import type { Hono } from "hono";
44
import { type Socket, Server as SocketIOServer } from "socket.io";
55
import { getUserIdFromToken } from "../../firebase/auth/db";
66

77
const users = new Map<UserID, Socket>();
88

99
export function initializeSocket(
10-
server: Server,
10+
app: Hono,
1111
corsOptions: {
1212
origin: string[];
1313
},
1414
) {
15+
const server = serve(app);
1516
const cors = {
1617
...corsOptions,
1718
origin: corsOptions.origin[0],
@@ -46,6 +47,8 @@ export function initializeSocket(
4647
}
4748
});
4849
});
50+
51+
return server;
4952
}
5053

5154
export function sendMessage(message: Message, friendId: UserID) {

0 commit comments

Comments
 (0)