-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 1.15 KB
/
index.js
File metadata and controls
39 lines (33 loc) · 1.15 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
require("dotenv").config();
const app = require("./app");
const connectionDb = require("./src/connection/connection.db");
const {socket} = require("./src/socket/SocketConnection");
const { Server } = require("socket.io");
async function main() {
try {
const PORT = process.env.PORT || 3008;
await connectionDb();
const server = app.listen(PORT,"0.0.0.0", () => {
console.log(`Server is Running http://localhost:${PORT}`);
});
// Set up Socket.IO-----------------
const socketIO = new Server(server, {
pingTimeout: 60000,
cors: {
origin: [
'http://localhost:52643', // Local development (e.g., Flutter web running on this port)
'https://your-live-website-url.com', // Production admin panel hosted on Cloudflare Pages (HTTPS)
'', // Optional: HTTP version in case SSL is not enforced (usually not needed)
'', // Production/staging admin panel hosted on Vercel
],
credentials: true,
},
});
socket(socketIO);
// Assign Socket.IO to globally available.
global.io = socketIO;
} catch (e) {
console.log(`Main Server Error ${e}`);
}
}
main();