-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
29 lines (24 loc) · 739 Bytes
/
server.ts
File metadata and controls
29 lines (24 loc) · 739 Bytes
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
import path from 'path';
import dotenv from 'dotenv';
import app from './app';
import socket from 'socket.io';
import chatFilter from './helpers/chatFilter/chatFilter';
dotenv.config({ path: path.join(__dirname, './env', '.env') });
const PORT = process.env.PORT! || 5000;
const server = app.listen(PORT, (): void => {
console.log(`Listening to request on port ${PORT}`);
});
const io = socket(server);
io.on('connection', (socket) => {
socket.on('chat-sent', (data) => {
console.log(data);
io.emit('broadcast-message', {
firstName: data.firstName,
lastName: data.lastName,
chat: chatFilter(data.chat),
createdAt: data.createdAt,
isAdmin: data.isAdmin,
id: socket.id,
});
});
});