Skip to content

Commit

Permalink
Merge pull request #3265 from processing/revert-3258-mongodb-connection
Browse files Browse the repository at this point in the history
Revert 3258 mongodb connection
  • Loading branch information
raclim authored Nov 4, 2024
2 parents ad6ae4b + 5c1ca07 commit bb6c883
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
5 changes: 4 additions & 1 deletion server/migrations/emailConsolidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const mongoConnectionString = process.env.MONGO_URL;
const { ObjectId } = mongoose.Types;
// Connect to MongoDB
mongoose.Promise = global.Promise;
mongoose.connect(mongoConnectionString);
mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.set('strictQuery', true);
mongoose.connection.on('error', () => {
console.error(
Expand Down
2 changes: 2 additions & 0 deletions server/previewServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const connectToMongoDB = async () => {
mongoose.set('strictQuery', true);

await mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 30000, // 30 seconds timeout
socketTimeoutMS: 45000 // 45 seconds timeout
});
Expand Down
5 changes: 4 additions & 1 deletion server/scripts/examples-gg-latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ const headers = { 'User-Agent': 'p5js-web-editor/0.0.1' };

const mongoConnectionString = process.env.MONGO_URL;

mongoose.connect(mongoConnectionString);
mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.set('strictQuery', true);
mongoose.connection.on('error', () => {
console.error(
Expand Down
5 changes: 4 additions & 1 deletion server/scripts/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const headers = { 'User-Agent': 'p5js-web-editor/0.0.1' };

const mongoConnectionString = process.env.MONGO_URL;

mongoose.connect(mongoConnectionString);
mongoose.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.set('strictQuery', true);
mongoose.connection.on('error', () => {
console.error(
Expand Down
24 changes: 10 additions & 14 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,14 @@ app.use(cookieParser());

mongoose.set('strictQuery', true);

async function connectToMongoDB() {
try {
const mongooseConnection = await mongoose.connect(mongoConnectionString, {
serverSelectionTimeoutMS: 30000, // 30 seconds timeout
socketTimeoutMS: 45000 // 45 seconds timeout
});
return mongooseConnection.connection.getClient();
} catch (err) {
throw new Error('MongoDB connection failed', err);
}
}

const clientInstancePromise = connectToMongoDB();
const clientPromise = mongoose
.connect(mongoConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 30000, // 30 seconds timeout
socketTimeoutMS: 45000 // 45 seconds timeout
})
.then((m) => m.connection.getClient());

app.use(
session({
Expand All @@ -102,7 +97,8 @@ app.use(
secure: false
},
store: new MongoStore({
clientPromise: clientInstancePromise
clientPromise,
autoReconnect: true
})
})
);
Expand Down

0 comments on commit bb6c883

Please sign in to comment.