Skip to content

Commit

Permalink
add timeout in previewServer
Browse files Browse the repository at this point in the history
  • Loading branch information
raclim committed Aug 22, 2024
1 parent 9f94d93 commit e31afef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server/previewServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ const mongoConnectionString = process.env.MONGO_URL;
// Connect to MongoDB
const connectToMongoDB = async () => {
try {
mongoose.set('strictQuery', true);

await mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true
useUnifiedTopology: true,
serverSelectionTimeoutMS: 30000, // 30 seconds timeout
socketTimeoutMS: 45000 // 45 seconds timeout
});
} catch (error) {
console.error('Failed to connect to MongoDB: ', error);
Expand All @@ -31,7 +35,6 @@ const connectToMongoDB = async () => {

connectToMongoDB();

mongoose.set('strictQuery', true);
mongoose.connection.on('error', () => {
console.error(
'MongoDB Connection Error. Please make sure that MongoDB is running.'
Expand Down

0 comments on commit e31afef

Please sign in to comment.