Skip to content

Commit e31afef

Browse files
committed
add timeout in previewServer
1 parent 9f94d93 commit e31afef

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

server/previewServer.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ const mongoConnectionString = process.env.MONGO_URL;
1919
// Connect to MongoDB
2020
const connectToMongoDB = async () => {
2121
try {
22+
mongoose.set('strictQuery', true);
23+
2224
await mongoose.connect(mongoConnectionString, {
2325
useNewUrlParser: true,
24-
useUnifiedTopology: true
26+
useUnifiedTopology: true,
27+
serverSelectionTimeoutMS: 30000, // 30 seconds timeout
28+
socketTimeoutMS: 45000 // 45 seconds timeout
2529
});
2630
} catch (error) {
2731
console.error('Failed to connect to MongoDB: ', error);
@@ -31,7 +35,6 @@ const connectToMongoDB = async () => {
3135

3236
connectToMongoDB();
3337

34-
mongoose.set('strictQuery', true);
3538
mongoose.connection.on('error', () => {
3639
console.error(
3740
'MongoDB Connection Error. Please make sure that MongoDB is running.'

0 commit comments

Comments
 (0)