Skip to content

Commit

Permalink
new attempt from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
sankhadip-roy committed Apr 26, 2024
1 parent 49ac6c3 commit 878ba41
Show file tree
Hide file tree
Showing 37 changed files with 4,646 additions and 19,944 deletions.
910 changes: 75 additions & 835 deletions server/package-lock.json → backend/package-lock.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "backend",
"version": "1.0.0",
"description": "chat room app backend",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "sankhadip roy",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.19.2",
"socket.io": "^4.7.5"
}
}
34 changes: 34 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const express = require('express')
const app = express();
const http = require("http");
const cors = require('cors');
const { Server } = require("socket.io");

app.use(cors());

const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: 'http://localhost:5173',
methods: ['GET', 'POST'],
},
});

io.on("connection", (socket) => {
console.log(`User connected ${socket.id}`);

// Handle 'send_message' event
socket.on('send_message', (data) => {
console.log(`Received message: ${data.message}`);
// Broadcast the message to all connected clients
io.emit('recive_message', data);
});

socket.on('disconnect', () => {
console.log('User disconnected');
});
});

server.listen(3001, () => {
console.log(`Example app listening on port 3001`);
});
Loading

0 comments on commit 878ba41

Please sign in to comment.