2018-12-20 14:14:12 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS103: Rewrite code to no longer use __guard__
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2018-12-20 14:14:14 -05:00
|
|
|
const logger = require('logger-sharelatex')
|
2021-07-12 12:47:21 -04:00
|
|
|
const settings = require('@overleaf/settings')
|
2014-08-15 05:50:36 -04:00
|
|
|
|
2020-08-19 08:06:22 -04:00
|
|
|
const mongodb = require('./app/js/mongodb')
|
2018-12-20 14:14:14 -05:00
|
|
|
const Server = require('./app/js/server')
|
2014-08-15 06:35:22 -04:00
|
|
|
|
2018-12-20 14:14:14 -05:00
|
|
|
if (!module.parent) {
|
|
|
|
// Called directly
|
|
|
|
const port =
|
|
|
|
__guard__(
|
|
|
|
settings.internal != null ? settings.internal.chat : undefined,
|
2021-07-13 07:04:48 -04:00
|
|
|
x => x.port
|
2018-12-20 14:14:14 -05:00
|
|
|
) || 3010
|
|
|
|
const host =
|
|
|
|
__guard__(
|
|
|
|
settings.internal != null ? settings.internal.chat : undefined,
|
2021-07-13 07:04:48 -04:00
|
|
|
x1 => x1.host
|
2018-12-20 14:14:14 -05:00
|
|
|
) || 'localhost'
|
2020-08-24 12:06:30 -04:00
|
|
|
mongodb
|
|
|
|
.waitForDb()
|
2020-08-19 08:06:22 -04:00
|
|
|
.then(() => {
|
|
|
|
Server.server.listen(port, host, function (err) {
|
|
|
|
if (err) {
|
|
|
|
logger.fatal({ err }, `Cannot bind to ${host}:${port}. Exiting.`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
return logger.info(`Chat starting up, listening on ${host}:${port}`)
|
|
|
|
})
|
|
|
|
})
|
2021-07-13 07:04:48 -04:00
|
|
|
.catch(err => {
|
2020-08-19 08:06:22 -04:00
|
|
|
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2018-12-20 14:14:12 -05:00
|
|
|
}
|
2014-08-15 06:35:22 -04:00
|
|
|
|
2018-12-20 14:14:14 -05:00
|
|
|
module.exports = Server.server
|
2018-12-20 14:14:12 -05:00
|
|
|
|
|
|
|
function __guard__(value, transform) {
|
2018-12-20 14:14:14 -05:00
|
|
|
return typeof value !== 'undefined' && value !== null
|
|
|
|
? transform(value)
|
|
|
|
: undefined
|
|
|
|
}
|