started dispatch-server

This commit is contained in:
PxlLoewe
2025-03-13 00:01:39 -07:00
parent e0703c0e33
commit ec335ce489
7 changed files with 1265 additions and 8 deletions

View File

@@ -0,0 +1,29 @@
import "dotenv/config";
import express from "express";
import { createServer } from "http";
import { handle } from "socket-events/connect-dispatch";
import { Server } from "socket.io";
import { createClient } from "redis";
import { createAdapter } from "@socket.io/redis-adapter";
const pubClient = createClient();
const subClient = pubClient.duplicate();
const app = express();
const server = createServer(app);
const initApp = async () => {
await Promise.all([pubClient.connect(), subClient.connect()]);
const io = new Server(server, {
adapter: createAdapter(pubClient, subClient),
});
io.on("connection", (socket) => {
socket.on("connect-dispatch", handle);
});
server.listen(process.env.PORT, () => {
console.log(`Server running on port ${process.env.PORT}`);
});
};
initApp();