2021-12-14 13:00:35 +00:00
|
|
|
const logger = require('@overleaf/logger')
|
2021-07-12 16:47:21 +00:00
|
|
|
const settings = require('@overleaf/settings')
|
2014-08-15 09:50:36 +00:00
|
|
|
|
2022-12-08 12:17:56 +00:00
|
|
|
const { mongoClient } = require('./app/js/mongodb')
|
2018-12-20 19:14:14 +00:00
|
|
|
const Server = require('./app/js/server')
|
2014-08-15 10:35:22 +00:00
|
|
|
|
2018-12-20 19:14:14 +00:00
|
|
|
if (!module.parent) {
|
|
|
|
// Called directly
|
2022-01-07 10:36:03 +00:00
|
|
|
const port = settings.internal.chat.port
|
|
|
|
const host = settings.internal.chat.host
|
2022-12-08 12:17:56 +00:00
|
|
|
mongoClient
|
|
|
|
.connect()
|
2020-08-19 12:06:22 +00:00
|
|
|
.then(() => {
|
|
|
|
Server.server.listen(port, host, function (err) {
|
|
|
|
if (err) {
|
|
|
|
logger.fatal({ err }, `Cannot bind to ${host}:${port}. Exiting.`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2022-05-16 12:38:18 +00:00
|
|
|
logger.debug(`Chat starting up, listening on ${host}:${port}`)
|
2020-08-19 12:06:22 +00:00
|
|
|
})
|
|
|
|
})
|
2021-07-13 11:04:48 +00:00
|
|
|
.catch(err => {
|
2020-08-19 12:06:22 +00:00
|
|
|
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2018-12-20 19:14:12 +00:00
|
|
|
}
|
2014-08-15 10:35:22 +00:00
|
|
|
|
2018-12-20 19:14:14 +00:00
|
|
|
module.exports = Server.server
|