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

@@ -12,3 +12,6 @@ DB_NAME=
JWT_SECRET=3123123213123
JWT_REFRESH_SECRET=75756756756
IO_REDIS_SERVER=
IO_REDIS_PORT=

View File

@@ -23,6 +23,7 @@
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"http-graceful-shutdown": "^2.3.2",
"jsonwebtoken": "^8.5.1",
"multer": "^1.4.2",
"mysql2": "^2.2.5",
@@ -33,6 +34,7 @@
"sequelize-cli": "^5.5.1",
"sequelize-typescript": "^1.1.0",
"socket.io": "^2.3.0",
"socket.io-redis": "^5.4.0",
"whatsapp-web.js": "1.11.0",
"yup": "^0.29.3"
},
@@ -49,6 +51,7 @@
"@types/multer": "^1.4.4",
"@types/node": "^14.11.8",
"@types/socket.io": "^2.1.11",
"@types/socket.io-redis": "^1.0.26",
"@types/supertest": "^2.0.10",
"@types/validator": "^13.1.0",
"@types/yup": "^0.29.8",

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 => {

View File

@@ -49,5 +49,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"devDependencies": {}
}