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,3 @@
PORT=3002
REDIS_HOST=localhost
REDIS_PORT=6379

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();

View File

@@ -0,0 +1,5 @@
{
"watch": ["."],
"ext": "ts",
"exec": "tsx index.ts"
}

View File

@@ -0,0 +1,33 @@
{
"name": "dispatch-server",
"exports": {
"helpers": "./helper"
},
"scripts": {
"dev": "nodemon",
"build": "tsc"
},
"devDependencies": {
"@repo/db": "*",
"@repo/typescript-config": "*",
"@types/express": "^5.0.0",
"@types/node": "^22.13.5",
"@types/nodemailer": "^6.4.17",
"@types/socket.io-redis": "^1.0.27",
"concurrently": "^9.1.2",
"typescript": "latest"
},
"dependencies": {
"@react-email/components": "^0.0.32",
"@socket.io/redis-adapter": "^8.3.0",
"axios": "^1.7.9",
"cron": "^4.1.0",
"dotenv": "^16.4.7",
"express": "^4.21.2",
"nodemailer": "^6.10.0",
"react": "^19.0.0",
"redis": "^4.7.0",
"socket.io": "^4.8.1",
"socket.io-redis": "^5.4.0"
}
}

View File

@@ -0,0 +1,8 @@
import { Server, Socket } from "socket.io";
export const handle = async (socket: Socket, io: Server) => {
console.log("Connected to dispatch server");
socket.on("disconnect", () => {
console.log("Disconnected from dispatch server");
});
};

View File

@@ -0,0 +1,11 @@
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"outDir": "dist",
"allowImportingTsExtensions": false,
"baseUrl": ".",
"jsx": "react"
},
"include": ["**/*.ts", "./index.ts"],
"exclude": ["node_modules", "dist"]
}