krishgokul92 commited on
Commit
651e4af
·
verified ·
1 Parent(s): 8e05be8

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +4 -7
server.js CHANGED
@@ -11,26 +11,23 @@ const io = new Server(server, {
11
  cors: { origin: true }
12
  });
13
 
14
- // Serve static files
15
  app.use(express.static(path.join(__dirname, 'public')));
16
 
17
- // Handle root as redirect to /admin by default
18
- app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html')));
19
-
20
- // Serve /admin and /client dynamically (handling routing for both)
21
  app.get('/admin', (req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html')));
22
  app.get('/client', (req, res) => res.sendFile(path.join(__dirname, 'public', 'client.html')));
23
 
24
  const HOST = '0.0.0.0';
25
  const PORT = process.env.PORT || 7860;
26
 
27
- // Socket.io handling
28
  io.on('connection', (socket) => {
29
  const room = socket.handshake.query.room || 'default';
30
  const role = socket.handshake.query.role || 'client';
31
  socket.join(room);
32
 
33
- // Emit stats about room
34
  socket.on('sync:ping', (msg = {}) => {
35
  const t1 = Date.now();
36
  socket.emit('sync:pong', { t0: msg.t0, t1, t2: Date.now() });
 
11
  cors: { origin: true }
12
  });
13
 
14
+ // Serve static files from /public
15
  app.use(express.static(path.join(__dirname, 'public')));
16
 
17
+ // Fix: Ensure routes for /admin and /client work
18
+ app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html'))); // Default is admin
 
 
19
  app.get('/admin', (req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html')));
20
  app.get('/client', (req, res) => res.sendFile(path.join(__dirname, 'public', 'client.html')));
21
 
22
  const HOST = '0.0.0.0';
23
  const PORT = process.env.PORT || 7860;
24
 
25
+ // Socket handling
26
  io.on('connection', (socket) => {
27
  const room = socket.handshake.query.room || 'default';
28
  const role = socket.handshake.query.role || 'client';
29
  socket.join(room);
30
 
 
31
  socket.on('sync:ping', (msg = {}) => {
32
  const t1 = Date.now();
33
  socket.emit('sync:pong', { t0: msg.t0, t1, t2: Date.now() });