30 lines
800 B
TypeScript
30 lines
800 B
TypeScript
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();
|