Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
AkarshanGhosh committed Jan 21, 2025
1 parent 66540f1 commit 5cdf2c3
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ const connectToMongo = require('./db'); // Connection for the login database
// const connectToDivisionDB = require('./divisiondb'); // Connection for the division database
// const connectToTrainDB = require('./traindb.js'); // Connecting to coach db

// Import express and socket.io
// Import express, cors, and http
const express = require('express');
const cors = require('cors'); // Import the cors package
const socketIo = require('socket.io'); // Import socket.io
const http = require('http'); // Import http for Socket.IO
//const https = require('https')

// Create an instance of the Express application
const app = express();
const port = process.env.PORT || 5002; // Define the port number
const port = process.env.PORT || 5000; // Define the port number

// Middleware to parse incoming JSON requests
app.use(express.json());
Expand Down Expand Up @@ -49,13 +50,11 @@ connectToMongo();
// Connect to MongoDB for Train Database
// connectToTrainDB();

// Start the server with Express
const server = app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});
// Create an HTTP server using the Express app
const server = https.createServer(app);

// Integrate Socket.IO with the server
const io = socketIo(server, {
const io = require('socket.io')(server, {
cors: {
origin: allowedOrigins,
methods: ['GET', 'POST']
Expand Down Expand Up @@ -84,10 +83,7 @@ app.use('/api/auth', require('./routes/auth')); // Auth routes
app.use('/api/division', require('./routes/division')); // Division routes
app.use('/api/train', require('./routes/train')); // Train routes


// Start the server and listen on the defined port
//server.listen(port, '0.0.0.0', () => { // Listen on all network interfaces
// console.log(`Server is running and listening on https://0.0.0.0:${port}`);
//});

// Start the server
server.listen(port, '0.0.0.0', () => { // Listen on all network interfaces
console.log(`Server is running and listening on https://0.0.0.0:${port}`);
});

0 comments on commit 5cdf2c3

Please sign in to comment.