-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (38 loc) · 988 Bytes
/
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
var app = require('express')();
var http = require('http').createServer(app);
const socketio = require('socket.io');
const io = socketio(http,
//Local
// {
// serveClient: true,
// cors: {
// origin: "http://localhost:4200",
// methods: ["GET", "POST"],
// credentials: true
// }
// });
//Prod
{
serveClient: true,
cors: {
origin: "https://betweenus-app.herokuapp.com",
methods: ["GET", "POST"],
credentials: true
}
});
io.on('connection', (socket) => {
socket.on('message', (msg) => {
socket.broadcast.emit('message-broadcast', msg);
});
console.log('a user connected');
});
//Local
// app.get('/', (req, res) => res.send('hello!'));
// http.listen(3000, () => {
// console.log('listening on *:3000');
// });
//Prod
app.get('/', (req, res) => res.send('hello!'));
http.listen(process.env.PORT, () => {
console.log('listening on *:3000');
});