Skip to content

Commit 8f394e8

Browse files
committed
fix bug
1 parent b556854 commit 8f394e8

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

server/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,16 @@ mongoose.connect(mongoURI)
5151
.then(() => {
5252
dbReady = true;
5353
console.log('MongoDB connected');
54+
55+
// Start server only after DB connection is established
56+
server.listen(PORT, () => {
57+
console.log(`Server running on PORT: ${PORT}`);
58+
});
5459
})
5560
.catch(err => {
5661
console.error('MongoDB connection error:', err);
5762
dbReady = false;
63+
// Handle case where DB connection fails and don't start the server
5864
});
5965

6066
// Socket.IO Connection and Driver Tracking
@@ -641,7 +647,4 @@ app.get('/api/history', async (req, res) => {
641647
res.status(500).json({ status: 'error', message: 'An error occurred while fetching shipment data.' });
642648
}
643649
});
644-
// Start Server
645-
server.listen(PORT, () => {
646-
console.log(` Server running on PORT: ${PORT}`);
647-
});
650+

0 commit comments

Comments
 (0)