From 181f9f88fb6620964530b37ca5cdd3ccb2693904 Mon Sep 17 00:00:00 2001 From: Alf Eaton <75253002+aeaton-overleaf@users.noreply.github.com> Date: Mon, 18 Jan 2021 15:29:24 +0000 Subject: [PATCH] Merge pull request #3568 from overleaf/ae-mongo-promises Wait for mongoose to connect before starting the server GitOrigin-RevId: 4b470369b070f17b32e47106fada7cb4adf2a12c --- services/web/app.js | 4 ++-- services/web/app/src/infrastructure/Mongoose.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/web/app.js b/services/web/app.js index 16c49d8229..6bdc71a9b7 100644 --- a/services/web/app.js +++ b/services/web/app.js @@ -25,6 +25,7 @@ if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) { metrics.memory.monitor(logger) const Server = require('./app/src/infrastructure/Server') const mongodb = require('./app/src/infrastructure/mongodb') +const mongoose = require('./app/src/infrastructure/Mongoose') const Queues = require('./app/src/infrastructure/Queues') Queues.initialize() @@ -44,8 +45,7 @@ if (!module.parent) { if (!process.env.WEB_API_USER || !process.env.WEB_API_PASSWORD) { throw new Error('No API user and password provided') } - mongodb - .waitForDb() + Promise.all([mongodb.waitForDb(), mongoose.connectionPromise]) .then(() => { Server.server.listen(port, host, function() { logger.info(`web starting up, listening on ${host}:${port}`) diff --git a/services/web/app/src/infrastructure/Mongoose.js b/services/web/app/src/infrastructure/Mongoose.js index 6bfa6f0ad6..413d3781c6 100644 --- a/services/web/app/src/infrastructure/Mongoose.js +++ b/services/web/app/src/infrastructure/Mongoose.js @@ -56,5 +56,6 @@ async function getNativeDb() { } mongoose.getNativeDb = getNativeDb +mongoose.connectionPromise = connectionPromise module.exports = mongoose