-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (36 loc) · 1.27 KB
/
Copy pathindex.js
File metadata and controls
50 lines (36 loc) · 1.27 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
import dotenv from "dotenv";
import connectDatabase from "./src/database/connection.js";
import app from "./app.js";
import { createServer } from "http"; // Import createServer for Socket.io
import { Server } from "socket.io"; // Import Socket.io
import socketController from "./src/socket/socketController.js";
import firebaseInit from "./src/config/firebase.js";
import databaseSeeder from "./src/database/databaseSeeder.js";
dotenv.config({
path: "./.env"
});
const port = process.env.PORT;
// If database is connected, start the Express server and Socket.io
connectDatabase().then(async () => {
// await databaseSeeder();
// init firebase
await firebaseInit();
const httpServer = createServer(app);
// Attach socket.io to the HTTP server
const io = new Server(httpServer, {
cors: {
origin: "*", // Allow all origins for simplicity (change for production)
methods: ["GET", "POST"],
credentials: true
}
});
// init
socketController(io);
await databaseSeeder();
// Start the server on port 5050
httpServer.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
}).catch((error) => {
console.log("MongoDB connection Failed: ", error);
});