68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
const express = require('express');
|
|
const logger = require('./app/logger');
|
|
const port = process.env.PORT || 3040;
|
|
const db = require('./app/db')
|
|
const app = express();
|
|
const http = require("http");
|
|
const { Server } = require("socket.io");
|
|
const cors = require("cors");
|
|
|
|
app.use(cors());
|
|
|
|
const server = http.createServer(app);
|
|
|
|
console.log("ENTER THE SOCKET");
|
|
|
|
//console.log(server);
|
|
//console.log(http);
|
|
|
|
const io = new Server(server, {
|
|
cors: {
|
|
origin: [
|
|
'http://localhost:3000',
|
|
'http://localhost:5001',
|
|
'http://localhost:9080/',
|
|
'http://localhost:8090/',
|
|
'http://10.10.33.15',
|
|
'http://10.10.10.13',
|
|
'http://10.10.10.13:8090',
|
|
'https://dev-panel.mermsemr.com/',
|
|
'https://qa-panel.mermsemr.com/',
|
|
'https://panel.mermsemr.com/',
|
|
'https://works.mermsemr.com/',
|
|
'http://work.mermsemr.com/',
|
|
'https://users.mermsemr.com/',
|
|
'http://dev-socket.mermsemr.com',
|
|
'https://socket-dev.mermsemr.com',
|
|
'https://socket.mermsemr.com',
|
|
'*','*:*'],
|
|
methods: ["GET", "POST"],
|
|
},
|
|
});
|
|
|
|
//io.origins('*:*') // for latest version
|
|
|
|
io.on("connection", (socket) => {
|
|
console.log(`User Connected: ${socket.id}`);
|
|
|
|
socket.on("join_room", (data) => {
|
|
socket.join(data);
|
|
console.log(data);
|
|
});
|
|
|
|
socket.on("send_message", (data) => {
|
|
// console.log("send_message", data.room);
|
|
console.log("START ************************send_message");
|
|
console.log("send_message ", data.room);
|
|
console.log("send_message DATA ", data);
|
|
console.log("END ************************send_message");
|
|
socket.to(data.room).emit("receive_message", data);
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(port, () => {
|
|
console.log(`SERVER IS RUNNING on ${port}`);
|
|
});
|
|
|
|
//https://github.com/lemoncode21/nodejs-kafka/blob/master/index.js
|