started dispatch-server
This commit is contained in:
3
apps/dispatch-server/.env.example
Normal file
3
apps/dispatch-server/.env.example
Normal file
@@ -0,0 +1,3 @@
|
||||
PORT=3002
|
||||
REDIS_HOST=localhost
|
||||
REDIS_PORT=6379
|
||||
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();
|
||||
5
apps/dispatch-server/nodemon.json
Normal file
5
apps/dispatch-server/nodemon.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"watch": ["."],
|
||||
"ext": "ts",
|
||||
"exec": "tsx index.ts"
|
||||
}
|
||||
33
apps/dispatch-server/package.json
Normal file
33
apps/dispatch-server/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
8
apps/dispatch-server/socket-events/connect-dispatch.ts
Normal file
8
apps/dispatch-server/socket-events/connect-dispatch.ts
Normal 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");
|
||||
});
|
||||
};
|
||||
11
apps/dispatch-server/tsconfig.json
Normal file
11
apps/dispatch-server/tsconfig.json
Normal 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"]
|
||||
}
|
||||
1184
package-lock.json
generated
1184
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user