started dispatch-server
This commit is contained in:
29
apps/dispatch-server/index.ts
Normal file
29
apps/dispatch-server/index.ts
Normal 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();
|
||||
Reference in New Issue
Block a user