-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
25 lines (20 loc) · 768 Bytes
/
server.js
File metadata and controls
25 lines (20 loc) · 768 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
// server.js (Final Version)
const express = require('express');
const http = require('http');
const { Server } = require('socket.io');
const path = require('path');
const handleSocketEvents = require('./socketHandler'); // <-- Import our new handler
const app = express();
const server = http.createServer(app);
const io = new Server(server);
// This part is important for serving the React App
app.use(express.static('build'));
app.use((req, res, next) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Hand off all socket connection logic to our handler
io.on('connection', (socket) => {
handleSocketEvents(io, socket);
});
const PORT = process.env.PORT || 4000;
server.listen(PORT, () => console.log(`Listening on port ${PORT}`));