File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change
1
+ const http = require ( 'http' ) ;
1
2
const polka = require ( 'polka' ) ;
2
- const static = require ( 'serve-static' ) ;
3
+ const io = require ( 'socket.io' ) ;
4
+ const sirv = require ( 'sirv' ) ;
3
5
4
6
const { PORT = 3000 } = process . env ;
5
7
6
- const { server } = polka ( ) . use ( static ( 'public' ) ) ;
7
- const io = require ( 'socket.io' ) ( server ) ;
8
+ const files = sirv ( 'public' ) ;
9
+ const server = http . createServer ( ) ;
8
10
9
- server . listen ( PORT , _ => {
11
+ polka ( { server } ) . use ( files ) . listen ( PORT ) . then ( ( ) => {
10
12
console . log ( `> Running on localhost:${ PORT } ` ) ;
11
13
} ) ;
12
14
13
15
// Chatroom
14
16
let numUsers = 0 ;
15
- io . on ( 'connection' , socket => {
17
+ io ( server ) . on ( 'connection' , socket => {
16
18
let added = false ;
17
19
18
20
// when the client emits 'new message', this listens and executes
Original file line number Diff line number Diff line change 4
4
},
5
5
"dependencies" : {
6
6
"polka" : " latest" ,
7
- "serve-static " : " ^1.13.1 " ,
8
- "socket.io" : " ^2.0.4 "
7
+ "sirv " : " latest " ,
8
+ "socket.io" : " latest "
9
9
}
10
10
}
You can’t perform that action at this time.
0 commit comments