mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-25 22:11:17 +00:00
f7275a6c4b
Upgrade logger and metrics in all services GitOrigin-RevId: 2baf63eeeab77fb3559cf763ddacfbf4b745cd0b
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/*
|
|
* 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
|
|
*/
|
|
const logger = require('@overleaf/logger')
|
|
const settings = require('@overleaf/settings')
|
|
|
|
const mongodb = require('./app/js/mongodb')
|
|
const Server = require('./app/js/server')
|
|
|
|
if (!module.parent) {
|
|
// Called directly
|
|
const port =
|
|
__guard__(
|
|
settings.internal != null ? settings.internal.chat : undefined,
|
|
x => x.port
|
|
) || 3010
|
|
const host =
|
|
__guard__(
|
|
settings.internal != null ? settings.internal.chat : undefined,
|
|
x1 => x1.host
|
|
) || 'localhost'
|
|
mongodb
|
|
.waitForDb()
|
|
.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}`)
|
|
})
|
|
})
|
|
.catch(err => {
|
|
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
|
|
process.exit(1)
|
|
})
|
|
}
|
|
|
|
module.exports = Server.server
|
|
|
|
function __guard__(value, transform) {
|
|
return typeof value !== 'undefined' && value !== null
|
|
? transform(value)
|
|
: undefined
|
|
}
|