-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (40 loc) · 1.12 KB
/
server.js
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
const express = require('express');
const { Server } = require('socket.io');
const http = require('http');
const cors = require('cors');
const path = require('path');
const app = express();
port = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: "*"
}
});
// const io = new Server(server, {
// cors: {
// origin: "https://react-on-chatter-6ef12e3df9fb.herokuapp.com/",
// // origin: "https://react-on-chatter-6ef12e3df9fb.herokuapp.com/",
// methods: ["GET", "POST"]
// },
// })
app.get('/', (req, res) => {
res.send({
"message": "Hello from Server",
"nikhil": "hello Nikhil!",
"metho": "adding cors: '*' "
});
});
server.listen(port, () => {
console.log("server is running at http://localhost:"+port)
});
io.on('connection', (socket)=> {
console.log("New WS Connection");
console.log(socket.id)
socket.on("message", (message) => {
console.log(message)
socket.emit("everyone-recieve-it", {"STC" : message})
});
});