Commit cf48c6e 1 parent af41548 commit cf48c6e Copy full SHA for cf48c6e
File tree 5 files changed +29
-1
lines changed
5 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 6
6
"dev" : " bun run --watch src/index.ts"
7
7
},
8
8
"dependencies" : {
9
+ "@elysiajs/static" : " ^1.1.1" ,
9
10
"elysia" : " latest"
10
11
},
11
12
"devDependencies" : {
Original file line number Diff line number Diff line change
1
+ ../../client/dist
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change 1
1
import { Elysia } from "elysia" ;
2
+ import { staticPlugin } from "@elysiajs/static" ;
2
3
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 ) ;
4
24
5
25
console . log (
6
26
`🦊 Elysia is running at ${ app . server ?. hostname } :${ app . server ?. port } `
You can’t perform that action at this time.
0 commit comments