-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (45 loc) · 1.12 KB
/
index.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
50
51
// Requirements
const express = require('express');
const helmet = require('helmet');
const { router } = require('./routes/router');
const { friendRouter } = require('./routes/friend-routes');
const cors = require('cors');
//App configuration
const app = express();
require('dotenv').config();
// Middlewares
app.use(
cors({
"origin": 'http://localhost:8080',
})
);
app.use(express.static('public/dist'));
app.use(require('body-parser').json());
app.use('/auth/', router);
app.use('/api/friends/', friendRouter);
app.use(
helmet({
contentSecurityPolicy: false,
})
);
//Process env destructure
const { PORT } = process.env;
const http = require('http').createServer(app);
const io = require('socket.io')(http,{
cors: {
origin: "http://localhost:8080",
credentials: true
},
path: '/socket',
allowEIO3: true
});
io.on('connection', (socket)=>{
console.log("user connected ")
socket.on('message', function(msg){
io.emit('customEmit', {message: 'yey'})
console.log('message arrived ', msg)
})
})
http.listen(PORT, () => {
console.log(`Server up and running! -> http://localhost:${PORT}`);
});