Skip to content

Commit a9f0f58

Browse files
committed
example: fix with-socketio demo;
- needed update after [email protected] - the “socket.io” binding needs to come _after_ main server - swapped “serve-static” w/ “sirv”
1 parent 734ee31 commit a9f0f58

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

examples/with-socketio/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
const http = require('http');
12
const polka = require('polka');
2-
const static = require('serve-static');
3+
const io = require('socket.io');
4+
const sirv = require('sirv');
35

46
const { PORT=3000 } = process.env;
57

6-
const { server } = polka().use(static('public'));
7-
const io = require('socket.io')(server);
8+
const files = sirv('public');
9+
const server = http.createServer();
810

9-
server.listen(PORT, _ => {
11+
polka({ server }).use(files).listen(PORT).then(() => {
1012
console.log(`> Running on localhost:${PORT}`);
1113
});
1214

1315
// Chatroom
1416
let numUsers = 0;
15-
io.on('connection', socket => {
17+
io(server).on('connection', socket => {
1618
let added = false;
1719

1820
// when the client emits 'new message', this listens and executes

examples/with-socketio/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
},
55
"dependencies": {
66
"polka": "latest",
7-
"serve-static": "^1.13.1",
8-
"socket.io": "^2.0.4"
7+
"sirv": "latest",
8+
"socket.io": "latest"
99
}
1010
}

0 commit comments

Comments
 (0)