This repository was archived by the owner on Nov 20, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 668
Expand file tree
/
Copy pathinit.js
More file actions
executable file
·41 lines (34 loc) · 1.51 KB
/
init.js
File metadata and controls
executable file
·41 lines (34 loc) · 1.51 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
// Import required modules
const socketIO = require("socket.io"); // For real-time WebSocket communication
const express = require("express"); // Web framework for Node.js
const path = require("path"); // Utility for handling file and directory paths
const http = require("http"); // Node.js HTTP server
const app = express(); // Create an Express application
// Import configuration and signalling server logic
const config = require("./server/config");
const signallingServer = require("./server/signalling-server");
const routes = require("./server/routes");
// Get PORT from env variable else assign 3000 for development
const PORT = config.PORT || 824;
const server = http.createServer(app); // Create HTTP server with Express app
// Set EJS as the view engine for rendering templates
app.set("view engine", "ejs");
// Serve static files from Vue, assets, and www directories
app.use(express.static(path.join(__dirname, "node_modules/vue/dist/")));
app.use(express.static(path.join(__dirname, "public/icons")));
app.use(express.static(path.join(__dirname, "public"), { maxAge: 0 })); // No cache for www
// Initialize Socket.IO and attach signalling server logic
const io = socketIO(server, {
cors: {
origin: config.CORS_ORIGIN,
methods: ["GET", "POST"],
credentials: true,
},
});
io.sockets.on("connection", signallingServer);
app.use("/", routes);
// Start the server and log status
server.listen(PORT, null, () => {
console.log("Hello server started");
console.log({ port: PORT, node_version: process.versions.node });
});