-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
60 lines (44 loc) · 1.25 KB
/
index.ts
File metadata and controls
60 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import express, { Application } from "express";
import connectDB from "./dbConnection";
import { startScheduler } from "./bot/bot";
import dotenv from "dotenv";
import { createServer } from "http";
import { Server } from "socket.io";
import cors from "cors";
dotenv.config();
const PORT: number = parseInt(process.env.PORT_NUMBER || "5000");
// connecting the db
connectDB();
const app: Application = express();
app.use(
cors({
origin: "*",
})
);
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: "http://localhost:3000",
},
});
io.on("connection", async (socket) => {
console.log("connected", socket.id);
socket.on("disconnect", function () {
console.log("user disconnected");
socket.removeAllListeners();
});
});
app.use(express.json());
// routes
import adminRoutes from "./routes/admin.routes";
import tradeScheduleRoutes from "./routes/tradeSchedule.routes";
import botRoutes from "./routes/bot.routes";
app.use("/api/v1/", adminRoutes);
app.use("/api/v1/", tradeScheduleRoutes);
app.use("/api/v1/", botRoutes);
// starting the scheduler (every second)
startScheduler(io);
// httpServer.listen(3000);
httpServer.listen(PORT, () => {
console.log(`app is running on port ${PORT}`);
});