-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cjs
More file actions
50 lines (42 loc) · 1.59 KB
/
Copy pathserver.cjs
File metadata and controls
50 lines (42 loc) · 1.59 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// // server.js
// const express = require('express');
// const http = require('http');
// const { Server } = require('socket.io');
// const cors = require('cors');
// const app = express();
// const server = http.createServer(app);
// // Configure CORS to allow requests from both portals
// const io = new Server(server, {
// cors: {
// origin: ['http://localhost:3000', 'http://localhost:3001'], // Adjust ports as needed
// methods: ['GET', 'POST'],
// credentials: true,
// },
// });
// // Middleware
// app.use(cors());
// app.use(express.json());
// // Handle Socket.IO connections
// io.on('connection', (socket) => {
// console.log(`New client connected: ${socket.id}`);
// // Handle user joining with a specific role
// socket.on('join', ({ role, userId }) => {
// socket.join(role); // e.g., 'client' or 'stylist'
// socket.join(userId); // Join a room specific to the user for direct messaging
// console.log(`${role} joined with ID: ${userId}`);
// });
// // Handle sending private messages
// socket.on('private_message', ({ content, to, from }) => {
// // Emit the message to the recipient's room
// io.to(to).emit('private_message', { content, from });
// console.log(`Message from ${from} to ${to}: ${content}`);
// });
// socket.on('disconnect', () => {
// console.log(`Client disconnected: ${socket.id}`);
// });
// });
// // Start the server
// const PORT = process.env.PORT || 3002; // Use a different port for the socket server
// server.listen(PORT, () => {
// console.log(`Socket.IO server running on http://localhost:${PORT}`);
// });