-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 837 Bytes
/
server.js
File metadata and controls
29 lines (24 loc) · 837 Bytes
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
import express from 'express';
import http from 'http';
import { Server } from 'socket.io';
import cors from 'cors';
const app = express();
app.use(cors({ origin: '*' }));
app.use(express.json());
app.get('/api/blueprints/:author/:name', (req, res) => {
res.json({
author: req.params.author,
name: req.params.name,
points: [{ x: 10, y: 10 }, { x: 40, y: 50 }],
});
});
const server = http.createServer(app);
const io = new Server(server, { cors: { origin: '*' } });
io.on('connection', (socket) => {
socket.on('join-room', (room) => socket.join(room));
socket.on('draw-event', ({ room, point, author, name }) => {
socket.to(room).emit('blueprint-update', { author, name, points: [point] });
});
});
const PORT = process.env.PORT || 3001;
server.listen(PORT, () => console.log(`Socket.IO up on :${PORT}`));