redis pub/sub fix
This commit is contained in:
10
io.js
10
io.js
@@ -1,7 +1,7 @@
|
||||
import {createServer} from "http";
|
||||
import {Server} from "socket.io";
|
||||
import { createAdapter } from "@socket.io/redis-adapter";
|
||||
import {redis} from "./cache.js";
|
||||
import {redis, redisSubscriber} from "./cache.js";
|
||||
import {fileURLToPath} from "url";
|
||||
import path from "path";
|
||||
import express from "express";
|
||||
@@ -29,12 +29,14 @@ app.set('views', path.join(__dirname, 'views')); // Set the views directory
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.use(cors())
|
||||
app.use((err, req, res, next) => {
|
||||
console.error(err.stack);
|
||||
res.status(500).send('Something went wrong!');
|
||||
});
|
||||
|
||||
initSnapShare(app)
|
||||
|
||||
export const httpServer = createServer(app)
|
||||
export const io = new Server(httpServer, socketIoOptions)
|
||||
const pubClient = redis.duplicate();
|
||||
await pubClient.connect()
|
||||
const adapter = createAdapter(pubClient, redis, {/*key:'socket.io'*/})
|
||||
const adapter = createAdapter(redis, redisSubscriber, {/*key:'socket.io'*/})
|
||||
io.adapter(adapter)
|
||||
|
||||
Reference in New Issue
Block a user