chore: add socket-redis config for multinode use

This commit is contained in:
canove
2020-11-07 17:29:44 -03:00
parent 1e1e48d0a3
commit 5b4969f992
4 changed files with 17 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import socketIo, { Server as SocketIO } from "socket.io";
import socketRedis from "socket.io-redis";
import { Server } from "http";
import AppError from "../errors/AppError";
@@ -6,6 +7,14 @@ let io: SocketIO;
export const initIO = (httpServer: Server): SocketIO => {
io = socketIo(httpServer);
if (process.env.IO_REDIS_SERVER) {
io.adapter(
socketRedis({
host: process.env.IO_REDIS_SERVER,
port: Number(process.env.IO_REDIS_PORT)
})
);
}
io.on("connection", socket => {
console.log("Client Connected");
socket.on("joinChatBox", ticketId => {