Skip to content

Commit cf48c6e

Browse files
committed
server: Finish implementation
1 parent af41548 commit cf48c6e

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

server/bun.lockb

1.07 KB
Binary file not shown.

server/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dev": "bun run --watch src/index.ts"
77
},
88
"dependencies": {
9+
"@elysiajs/static": "^1.1.1",
910
"elysia": "latest"
1011
},
1112
"devDependencies": {

server/public/dist

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../client/dist

server/public/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!doctype html>
2+
<meta charset=UTF-8>
3+
<title>채팅!</title>
4+
<link rel=stylesheet type=text/css href=dist/main.css>
5+
<div id=target></div>
6+
<script src=dist/main.js></script>

server/src/index.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import { Elysia } from "elysia";
2+
import { staticPlugin } from "@elysiajs/static";
23

3-
const app = new Elysia().get("/", () => "Hello Elysia").listen(4567);
4+
const sockets = new Map;
5+
6+
const app = new Elysia()
7+
.use(staticPlugin({ prefix: "/" }))
8+
.ws("/api", {
9+
open(ws) {
10+
sockets.set(ws.id, ws);
11+
},
12+
close(ws) {
13+
sockets.delete(ws.id);
14+
},
15+
message(ws, message) {
16+
for (const [id, socket] of sockets) {
17+
if (ws.id === id) continue;
18+
19+
socket.send(message);
20+
}
21+
},
22+
})
23+
.listen(4567);
424

525
console.log(
626
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`

0 commit comments

Comments
 (0)