-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (29 loc) · 801 Bytes
/
server.js
File metadata and controls
35 lines (29 loc) · 801 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
30
31
32
33
34
35
import { createServer } from 'http';
import { Server } from 'socket.io';
import {
ALLOWED_ORIGINS,
ENV,
PORT,
SOCKET_EVENTS,
} from './configuration/index.js';
import authorize from './middlewares/authorize.js';
import { client as redis } from './utilities/redis.js';
import log from './utilities/log.js';
import router from './router/index.js';
const httpServer = createServer();
const io = new Server(
httpServer,
{
cors: {
origin: ALLOWED_ORIGINS,
credentials: true,
},
},
);
io.use((socket, next) => authorize(socket, next));
io.on(SOCKET_EVENTS.CONNECTION, (socket) => router(socket, io));
redis.on('connect', () => log('-- redis: connected'));
httpServer.listen(
PORT,
() => log(`-- DEEPSEEN-WS is running on port ${PORT} [${ENV.toUpperCase()}]`),
);