-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
35 lines (26 loc) · 928 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const serverPort = 3000;
// Serve static assents in root directory
app.use(express.static(__dirname));
// Serve root path
app.get('/', (request, response) => {
//TODO eventually this should be index.html
response.sendFile(__dirname + '/bitStoryOnline.html');
});
// Listen for socket connections (taken from https://socket.io/get-started/chat/)
io.on('connection', (socket) => {
console.log("a user connected");
// Listen for blocks to be published
socket.on('publish-block', (b) => {
console.log("received a new block");
// Broadcast it to everyone (including original creator)
socket.broadcast.emit('gossip-block', b);
});
});
// Start the server running
http.listen(serverPort, () => {
console.log(`Started bitstory server on port ${serverPort}`)
})